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))
281 :group 'gnus-article-washing)
283 (defcustom gnus-article-x-face-too-ugly nil
284 "Regexp matching posters whose face shouldn't be shown automatically."
285 :type '(choice regexp (const nil))
286 :group 'gnus-article-washing)
288 (defcustom gnus-article-banner-alist nil
289 "Banner alist for stripping.
291 ((egroups . \"^[ \\t\\n]*-------------------+\\\\( \\\\(e\\\\|Yahoo! \\\\)Groups Sponsor -+\\\\)?....\\n\\\\(.+\\n\\\\)+\"))"
293 :type '(repeat (cons symbol regexp))
294 :group 'gnus-article-washing)
296 (gnus-define-group-parameter
299 "Alist of regexps (to match group names) and banner."
300 :variable-group gnus-article-washing
302 '(choice :tag "Banner"
304 (const :tag "Remove signature" signature)
305 (symbol :tag "Item in `gnus-article-banner-alist'" none)
307 (const :tag "None" nil))
309 "If non-nil, specify how to remove `banners' from articles.
311 Symbol `signature' means to remove signatures delimited by
312 `gnus-signature-separator'. Any other symbol is used to look up a
313 regular expression to match the banner in `gnus-article-banner-alist'.
314 A string is used as a regular expression to match the banner
317 (defcustom gnus-emphasis-alist
319 "\\(\\s-\\|^\\|\\=\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\\(\\([-,.;:!?\"]\\|\\s)\\)+\\s-\\|[?!.]\\s-\\|\\s)\\|\\s-\\)")
324 ("_/" "/_" underline-italic)
325 ("_\\*" "\\*_" underline-bold)
326 ("\\*/" "/\\*" bold-italic)
327 ("_\\*/" "/\\*_" underline-bold-italic))))
331 (format format (car spec) (car (cdr spec)))
332 2 3 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
334 ("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
335 2 3 gnus-emphasis-underline)))
336 "*Alist that says how to fontify certain phrases.
337 Each item looks like this:
339 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
341 The first element is a regular expression to be matched. The second
342 is a number that says what regular expression grouping used to find
343 the entire emphasized word. The third is a number that says what
344 regexp grouping should be displayed and highlighted. The fourth
345 is the face used for highlighting."
346 :type '(repeat (list :value ("" 0 0 default)
348 (integer :tag "Match group")
349 (integer :tag "Emphasize group")
351 :group 'gnus-article-emphasis)
353 (defcustom gnus-emphasize-whitespace-regexp "^[ \t]+\\|[ \t]*\n"
354 "A regexp to describe whitespace which should not be emphasized.
355 Typical values are \"^[ \\t]+\\\\|[ \\t]*\\n\" and \"[ \\t]+\\\\|[ \\t]*\\n\".
356 The former avoids underlining of leading and trailing whitespace,
357 and the latter avoids underlining any whitespace at all."
359 :group 'gnus-article-emphasis
362 (defface gnus-emphasis-bold '((t (:bold t)))
363 "Face used for displaying strong emphasized text (*word*)."
364 :group 'gnus-article-emphasis)
366 (defface gnus-emphasis-italic '((t (:italic t)))
367 "Face used for displaying italic emphasized text (/word/)."
368 :group 'gnus-article-emphasis)
370 (defface gnus-emphasis-underline '((t (:underline t)))
371 "Face used for displaying underlined emphasized text (_word_)."
372 :group 'gnus-article-emphasis)
374 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
375 "Face used for displaying underlined bold emphasized text (_*word*_)."
376 :group 'gnus-article-emphasis)
378 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
379 "Face used for displaying underlined italic emphasized text (_/word/_)."
380 :group 'gnus-article-emphasis)
382 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
383 "Face used for displaying bold italic emphasized text (/*word*/)."
384 :group 'gnus-article-emphasis)
386 (defface gnus-emphasis-underline-bold-italic
387 '((t (:bold t :italic t :underline t)))
388 "Face used for displaying underlined bold italic emphasized text.
389 Esample: (_/*word*/_)."
390 :group 'gnus-article-emphasis)
392 (defface gnus-emphasis-highlight-words
393 '((t (:background "black" :foreground "yellow")))
394 "Face used for displaying highlighted words."
395 :group 'gnus-article-emphasis)
397 (defcustom gnus-article-time-format "%a, %b %d %Y %T %Z"
398 "Format for display of Date headers in article bodies.
399 See `format-time-string' for the possible values.
401 The variable can also be function, which should return a complete Date
402 header. The function is called with one argument, the time, which can
403 be fed to `format-time-string'."
404 :type '(choice string symbol)
405 :link '(custom-manual "(gnus)Article Date")
406 :group 'gnus-article-washing)
409 (autoload 'mail-extract-address-components "mail-extr"))
411 (defcustom gnus-save-all-headers t
412 "*If non-nil, don't remove any headers before saving."
413 :group 'gnus-article-saving
416 (defcustom gnus-prompt-before-saving 'always
417 "*This variable says how much prompting is to be done when saving articles.
418 If it is nil, no prompting will be done, and the articles will be
419 saved to the default files. If this variable is `always', each and
420 every article that is saved will be preceded by a prompt, even when
421 saving large batches of articles. If this variable is neither nil not
422 `always', there the user will be prompted once for a file name for
423 each invocation of the saving commands."
424 :group 'gnus-article-saving
425 :type '(choice (item always)
426 (item :tag "never" nil)
427 (sexp :tag "once" :format "%t\n" :value t)))
429 (defcustom gnus-saved-headers gnus-visible-headers
430 "Headers to keep if `gnus-save-all-headers' is nil.
431 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
432 If that variable is nil, however, all headers that match this regexp
433 will be kept while the rest will be deleted before saving."
434 :group 'gnus-article-saving
437 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
438 "A function to save articles in your favourite format.
439 The function must be interactively callable (in other words, it must
440 be an Emacs command).
442 Gnus provides the following functions:
444 * gnus-summary-save-in-rmail (Rmail format)
445 * gnus-summary-save-in-mail (Unix mail format)
446 * gnus-summary-save-in-folder (MH folder)
447 * gnus-summary-save-in-file (article format)
448 * gnus-summary-save-body-in-file (article body)
449 * gnus-summary-save-in-vm (use VM's folder format)
450 * gnus-summary-write-to-file (article format -- overwrite)."
451 :group 'gnus-article-saving
452 :type '(radio (function-item gnus-summary-save-in-rmail)
453 (function-item gnus-summary-save-in-mail)
454 (function-item gnus-summary-save-in-folder)
455 (function-item gnus-summary-save-in-file)
456 (function-item gnus-summary-save-body-in-file)
457 (function-item gnus-summary-save-in-vm)
458 (function-item gnus-summary-write-to-file)))
460 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
461 "A function generating a file name to save articles in Rmail format.
462 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
463 :group 'gnus-article-saving
466 (defcustom gnus-mail-save-name 'gnus-plain-save-name
467 "A function generating a file name to save articles in Unix mail format.
468 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
469 :group 'gnus-article-saving
472 (defcustom gnus-folder-save-name 'gnus-folder-save-name
473 "A function generating a file name to save articles in MH folder.
474 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
475 :group 'gnus-article-saving
478 (defcustom gnus-file-save-name 'gnus-numeric-save-name
479 "A function generating a file name to save articles in article format.
480 The function is called with NEWSGROUP, HEADERS, and optional
482 :group 'gnus-article-saving
485 (defcustom gnus-split-methods
486 '((gnus-article-archive-name)
487 (gnus-article-nndoc-name))
488 "*Variable used to suggest where articles are to be saved.
489 For instance, if you would like to save articles related to Gnus in
490 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
491 you could set this variable to something like:
493 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
494 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
496 This variable is an alist where the where the key is the match and the
497 value is a list of possible files to save in if the match is non-nil.
499 If the match is a string, it is used as a regexp match on the
500 article. If the match is a symbol, that symbol will be funcalled
501 from the buffer of the article to be saved with the newsgroup as the
502 parameter. If it is a list, it will be evaled in the same buffer.
504 If this form or function returns a string, this string will be used as
505 a possible file name; and if it returns a non-nil list, that list will
506 be used as possible file names."
507 :group 'gnus-article-saving
508 :type '(repeat (choice (list :value (fun) function)
509 (cons :value ("" "") regexp (repeat string))
512 (defcustom gnus-article-display-method-for-mime
513 'gnus-article-display-mime-message
514 "Function to display a MIME message.
515 The function is called from the article buffer."
516 :group 'gnus-article-mime
519 (defcustom gnus-article-display-method-for-traditional
520 'gnus-article-display-traditional-message
521 "*Function to display a traditional message.
522 The function is called from the article buffer."
523 :group 'gnus-article-mime
526 (defcustom gnus-page-delimiter "^\^L"
527 "*Regexp describing what to use as article page delimiters.
528 The default value is \"^\^L\", which is a form linefeed at the
529 beginning of a line."
531 :group 'gnus-article-various)
533 (defcustom gnus-article-mode-line-format "Gnus: %g [%w] %S%m"
534 "*The format specification for the article mode line.
535 See `gnus-summary-mode-line-format' for a closer description.
537 The following additional specs are available:
539 %w The article washing status.
540 %m The number of MIME parts in the article."
542 :group 'gnus-article-various)
544 (defcustom gnus-article-mode-hook nil
545 "*A hook for Gnus article mode."
547 :group 'gnus-article-various)
549 (when (featurep 'xemacs)
550 ;; Extracted from gnus-xmas-define in order to preserve user settings
551 (when (fboundp 'turn-off-scroll-in-place)
552 (add-hook 'gnus-article-mode-hook 'turn-off-scroll-in-place))
553 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
554 (add-hook 'gnus-article-mode-hook 'gnus-xmas-article-menu-add))
556 (defcustom gnus-article-menu-hook nil
557 "*Hook run after the creation of the article mode menu."
559 :group 'gnus-article-various)
561 (defcustom gnus-article-prepare-hook nil
562 "*A hook called after an article has been prepared in the article buffer."
564 :group 'gnus-article-various)
566 (defcustom gnus-article-hide-pgp-hook nil
567 "*A hook called after successfully hiding a PGP signature."
569 :group 'gnus-article-various)
571 (defcustom gnus-article-button-face 'bold
572 "Face used for highlighting buttons in the article buffer.
574 An article button is a piece of text that you can activate by pressing
575 `RET' or `mouse-2' above it."
577 :group 'gnus-article-buttons)
579 (defcustom gnus-article-mouse-face 'highlight
580 "Face used for mouse highlighting in the article buffer.
582 Article buttons will be displayed in this face when the cursor is
585 :group 'gnus-article-buttons)
587 (defcustom gnus-signature-face 'gnus-signature-face
588 "Face used for highlighting a signature in the article buffer.
589 Obsolete; use the face `gnus-signature-face' for customizations instead."
591 :group 'gnus-article-highlight
592 :group 'gnus-article-signature)
594 (defface gnus-signature-face
597 "Face used for highlighting a signature in the article buffer."
598 :group 'gnus-article-highlight
599 :group 'gnus-article-signature)
601 (defface gnus-header-from-face
604 (:foreground "spring green"))
607 (:foreground "red3"))
610 "Face used for displaying from headers."
611 :group 'gnus-article-headers
612 :group 'gnus-article-highlight)
614 (defface gnus-header-subject-face
617 (:foreground "SeaGreen3"))
620 (:foreground "red4"))
622 (:bold t :italic t)))
623 "Face used for displaying subject headers."
624 :group 'gnus-article-headers
625 :group 'gnus-article-highlight)
627 (defface gnus-header-newsgroups-face
630 (:foreground "yellow" :italic t))
633 (:foreground "MidnightBlue" :italic t))
636 "Face used for displaying newsgroups headers."
637 :group 'gnus-article-headers
638 :group 'gnus-article-highlight)
640 (defface gnus-header-name-face
643 (:foreground "SeaGreen"))
646 (:foreground "maroon"))
649 "Face used for displaying header names."
650 :group 'gnus-article-headers
651 :group 'gnus-article-highlight)
653 (defface gnus-header-content-face
656 (:foreground "forest green" :italic t))
659 (:foreground "indianred4" :italic t))
662 "Face used for displaying header content."
663 :group 'gnus-article-headers
664 :group 'gnus-article-highlight)
666 (defcustom gnus-header-face-alist
667 '(("From" nil gnus-header-from-face)
668 ("Subject" nil gnus-header-subject-face)
669 ("Newsgroups:.*," nil gnus-header-newsgroups-face)
670 ("" gnus-header-name-face gnus-header-content-face))
671 "*Controls highlighting of article header.
673 An alist of the form (HEADER NAME CONTENT).
675 HEADER is a regular expression which should match the name of an
676 header header and NAME and CONTENT are either face names or nil.
678 The name of each header field will be displayed using the face
679 specified by the first element in the list where HEADER match the
680 header name and NAME is non-nil. Similarly, the content will be
681 displayed by the first non-nil matching CONTENT face."
682 :group 'gnus-article-headers
683 :group 'gnus-article-highlight
684 :type '(repeat (list (regexp :tag "Header")
686 (item :tag "skip" nil)
687 (face :value default))
688 (choice :tag "Content"
689 (item :tag "skip" nil)
690 (face :value default)))))
692 (defcustom gnus-article-decode-hook nil
693 "*Hook run to decode charsets in articles."
694 :group 'gnus-article-headers
697 (defcustom gnus-display-mime-function 'gnus-display-mime
698 "Function to display MIME articles."
699 :group 'gnus-article-mime
702 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
703 "Function used to decode headers.")
705 (defvar gnus-article-dumbquotes-map
724 "Table for MS-to-Latin1 translation.")
726 (defcustom gnus-ignored-mime-types nil
727 "List of MIME types that should be ignored by Gnus."
729 :group 'gnus-article-mime
730 :type '(repeat regexp))
732 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
733 "List of MIME types that should not be given buttons when rendered inline.
734 See also `gnus-buttonized-mime-types' which may override this variable."
736 :group 'gnus-article-mime
737 :type '(repeat regexp))
739 (defcustom gnus-buttonized-mime-types nil
740 "List of MIME types that should be given buttons when rendered inline.
741 If set, this variable overrides `gnus-unbuttonized-mime-types'.
742 To see e.g. security buttons you could set this to
743 `(\"multipart/signed\")'."
745 :group 'gnus-article-mime
746 :type '(repeat regexp))
748 (defcustom gnus-body-boundary-delimiter "_"
749 "String used to delimit header and body.
750 This variable is used by `gnus-article-treat-body-boundary' which can
751 be controlled by `gnus-treat-body-boundary'."
752 :group 'gnus-article-various
753 :type '(choice (item :tag "None" :value nil)
756 (defcustom gnus-picon-databases '("/usr/lib/picon" "/usr/local/faces")
757 "*Defines the location of the faces database.
758 For information on obtaining this database of pretty pictures, please
759 see http://www.cs.indiana.edu/picons/ftp/index.html"
763 (defun gnus-picons-installed-p ()
764 "Say whether picons are installed on your machine."
765 (let ((installed nil))
766 (dolist (database gnus-picon-databases)
767 (when (file-exists-p database)
771 (defcustom gnus-article-mime-part-function nil
772 "Function called with a MIME handle as the argument.
773 This is meant for people who want to do something automatic based
774 on parts -- for instance, adding Vcard info to a database."
775 :group 'gnus-article-mime
778 (defcustom gnus-mime-multipart-functions nil
779 "An alist of MIME types to functions to display them."
781 :group 'gnus-article-mime
784 (defcustom gnus-article-date-lapsed-new-header nil
785 "Whether the X-Sent and Date headers can coexist.
786 When using `gnus-treat-date-lapsed', the \"X-Sent:\" header will
787 either replace the old \"Date:\" header (if this variable is nil), or
788 be added below it (otherwise)."
790 :group 'gnus-article-headers
793 (defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
794 "Function called with a MIME handle as the argument.
795 This is meant for people who want to view first matched part.
796 For `undisplayed-alternative' (default), the first undisplayed
797 part or alternative part is used. For `undisplayed', the first
798 undisplayed part is used. For a function, the first part which
799 the function return `t' is used. For `nil', the first part is
802 :group 'gnus-article-mime
804 (item :tag "first" :value nil)
805 (item :tag "undisplayed" :value undisplayed)
806 (item :tag "undisplayed or alternative"
807 :value undisplayed-alternative)
810 (defcustom gnus-mime-action-alist
811 '(("save to file" . gnus-mime-save-part)
812 ("save and strip" . gnus-mime-save-part-and-strip)
813 ("display as text" . gnus-mime-inline-part)
814 ("view the part" . gnus-mime-view-part)
815 ("pipe to command" . gnus-mime-pipe-part)
816 ("toggle display" . gnus-article-press-button)
817 ("toggle display" . gnus-article-view-part-as-charset)
818 ("view as type" . gnus-mime-view-part-as-type)
819 ("internalize type" . gnus-mime-internalize-part)
820 ("externalize type" . gnus-mime-externalize-part))
821 "An alist of actions that run on the MIME attachment."
822 :group 'gnus-article-mime
823 :type '(repeat (cons (string :tag "name")
826 (defcustom gnus-mime-action-alist
827 '(("save to file" . gnus-mime-save-part)
828 ("display as text" . gnus-mime-inline-part)
829 ("view the part" . gnus-mime-view-part)
830 ("pipe to command" . gnus-mime-pipe-part)
831 ("toggle display" . gnus-article-press-button)
832 ("view as type" . gnus-mime-view-part-as-type)
833 ("internalize type" . gnus-mime-internalize-part)
834 ("externalize type" . gnus-mime-externalize-part))
835 "An alist of actions that run on the MIME attachment."
837 :group 'gnus-article-mime
838 :type '(repeat (cons (string :tag "name")
842 ;;; The treatment variables
845 (defvar gnus-part-display-hook nil
846 "Hook called on parts that are to receive treatment.")
848 (defvar gnus-article-treat-custom
849 '(choice (const :tag "Off" nil)
851 (const :tag "Header" head)
852 (const :tag "Last" last)
853 (const :tag "Mime" mime)
854 (integer :tag "Less")
855 (repeat :tag "Groups" regexp)
856 (sexp :tag "Predicate")))
858 (defvar gnus-article-treat-head-custom
859 '(choice (const :tag "Off" nil)
860 (const :tag "Header" head)))
862 (defvar gnus-article-treat-types '("text/plain")
865 (defvar gnus-inhibit-treatment nil
866 "Whether to inhibit treatment.")
868 (defcustom gnus-treat-highlight-signature '(or last (typep "text/x-vcard"))
869 "Highlight the signature.
870 Valid values are nil, t, `head', `last', an integer or a predicate.
871 See Info node `(gnus)Customizing Articles'."
872 :group 'gnus-article-treat
873 :type gnus-article-treat-custom)
874 (put 'gnus-treat-highlight-signature 'highlight t)
876 (defcustom gnus-treat-buttonize 100000
878 Valid values are nil, t, `head', `last', an integer or a predicate.
879 See Info node `(gnus)Customizing Articles'."
880 :group 'gnus-article-treat
881 :type gnus-article-treat-custom)
882 (put 'gnus-treat-buttonize 'highlight t)
884 (defcustom gnus-treat-buttonize-head 'head
885 "Add buttons to the head.
886 Valid values are nil, t, `head', `last', an integer or a predicate.
887 See Info node `(gnus)Customizing Articles' for details."
888 :group 'gnus-article-treat
889 :type gnus-article-treat-head-custom)
890 (put 'gnus-treat-buttonize-head 'highlight t)
892 (defcustom gnus-treat-emphasize
893 (and (or window-system
895 (>= (string-to-number emacs-version) 21))
898 Valid values are nil, t, `head', `last', an integer or a predicate.
899 See Info node `(gnus)Customizing Articles' for details."
900 :group 'gnus-article-treat
901 :type gnus-article-treat-custom)
902 (put 'gnus-treat-emphasize 'highlight t)
904 (defcustom gnus-treat-strip-cr nil
905 "Remove carriage returns.
906 Valid values are nil, t, `head', `last', an integer or a predicate.
907 See Info node `(gnus)Customizing Articles' for details."
908 :group 'gnus-article-treat
909 :type gnus-article-treat-custom)
911 (defcustom gnus-treat-unsplit-urls nil
912 "Remove newlines from within URLs.
913 Valid values are nil, t, `head', `last', an integer or a predicate.
914 See Info node `(gnus)Customizing Articles' for details."
915 :group 'gnus-article-treat
916 :type gnus-article-treat-custom)
918 (defcustom gnus-treat-leading-whitespace nil
919 "Remove leading whitespace in headers.
920 Valid values are nil, t, `head', `last', an integer or a predicate.
921 See Info node `(gnus)Customizing Articles' for details."
922 :group 'gnus-article-treat
923 :type gnus-article-treat-custom)
925 (defcustom gnus-treat-hide-headers 'head
927 Valid values are nil, t, `head', `last', an integer or a predicate.
928 See Info node `(gnus)Customizing Articles' for details."
929 :group 'gnus-article-treat
930 :type gnus-article-treat-head-custom)
932 (defcustom gnus-treat-hide-boring-headers nil
933 "Hide boring headers.
934 Valid values are nil, t, `head', `last', an integer or a predicate.
935 See Info node `(gnus)Customizing Articles' for details."
936 :group 'gnus-article-treat
937 :type gnus-article-treat-head-custom)
939 (defcustom gnus-treat-hide-signature nil
941 Valid values are nil, t, `head', `last', an integer or a predicate.
942 See Info node `(gnus)Customizing Articles' for details."
943 :group 'gnus-article-treat
944 :type gnus-article-treat-custom)
946 (defcustom gnus-treat-fill-article nil
948 Valid values are nil, t, `head', `last', an integer or a predicate.
949 See Info node `(gnus)Customizing Articles' for details."
950 :group 'gnus-article-treat
951 :type gnus-article-treat-custom)
953 (defcustom gnus-treat-hide-citation nil
955 Valid values are nil, t, `head', `last', an integer or a predicate.
956 See Info node `(gnus)Customizing Articles' for details."
957 :group 'gnus-article-treat
958 :type gnus-article-treat-custom)
960 (defcustom gnus-treat-hide-citation-maybe nil
962 Valid values are nil, t, `head', `last', an integer or a predicate.
963 See Info node `(gnus)Customizing Articles' for details."
964 :group 'gnus-article-treat
965 :type gnus-article-treat-custom)
967 (defcustom gnus-treat-strip-list-identifiers 'head
968 "Strip list identifiers from `gnus-list-identifiers`.
969 Valid values are nil, t, `head', `last', an integer or a predicate.
970 See Info node `(gnus)Customizing Articles' for details."
972 :group 'gnus-article-treat
973 :type gnus-article-treat-custom)
975 (defcustom gnus-treat-strip-pgp t
976 "Strip PGP signatures.
977 Valid values are nil, t, `head', `last', an integer or a predicate.
978 See Info node `(gnus)Customizing Articles' for details."
979 :group 'gnus-article-treat
980 :type gnus-article-treat-custom)
982 (defcustom gnus-treat-strip-pem nil
983 "Strip PEM signatures.
984 Valid values are nil, t, `head', `last', an integer or a predicate.
985 See Info node `(gnus)Customizing Articles' for details."
986 :group 'gnus-article-treat
987 :type gnus-article-treat-custom)
989 (defcustom gnus-treat-strip-banner t
990 "Strip banners from articles.
991 The banner to be stripped is specified in the `banner' group parameter.
992 Valid values are nil, t, `head', `last', an integer or a predicate.
993 See Info node `(gnus)Customizing Articles' for details."
994 :group 'gnus-article-treat
995 :type gnus-article-treat-custom)
997 (defcustom gnus-treat-highlight-headers 'head
998 "Highlight the headers.
999 Valid values are nil, t, `head', `last', an integer or a predicate.
1000 See Info node `(gnus)Customizing Articles' for details."
1001 :group 'gnus-article-treat
1002 :type gnus-article-treat-head-custom)
1003 (put 'gnus-treat-highlight-headers 'highlight t)
1005 (defcustom gnus-treat-highlight-citation t
1006 "Highlight cited text.
1007 Valid values are nil, t, `head', `last', an integer or a predicate.
1008 See Info node `(gnus)Customizing Articles' for details."
1009 :group 'gnus-article-treat
1010 :type gnus-article-treat-custom)
1011 (put 'gnus-treat-highlight-citation 'highlight t)
1013 (defcustom gnus-treat-date-ut nil
1014 "Display the Date in UT (GMT).
1015 Valid values are nil, t, `head', `last', an integer or a predicate.
1016 See Info node `(gnus)Customizing Articles' for details."
1017 :group 'gnus-article-treat
1018 :type gnus-article-treat-head-custom)
1020 (defcustom gnus-treat-date-local nil
1021 "Display the Date in the local timezone.
1022 Valid values are nil, t, `head', `last', an integer or a predicate.
1023 See Info node `(gnus)Customizing Articles' for details."
1024 :group 'gnus-article-treat
1025 :type gnus-article-treat-head-custom)
1027 (defcustom gnus-treat-date-english nil
1028 "Display the Date in a format that can be read aloud in English.
1029 Valid values are nil, t, `head', `last', an integer or a predicate.
1030 See Info node `(gnus)Customizing Articles' for details."
1031 :group 'gnus-article-treat
1032 :type gnus-article-treat-head-custom)
1034 (defcustom gnus-treat-date-lapsed nil
1035 "Display the Date header in a way that says how much time has elapsed.
1036 Valid values are nil, t, `head', `last', an integer or a predicate.
1037 See Info node `(gnus)Customizing Articles' for details."
1038 :group 'gnus-article-treat
1039 :type gnus-article-treat-head-custom)
1041 (defcustom gnus-treat-date-original nil
1042 "Display the date in the original timezone.
1043 Valid values are nil, t, `head', `last', an integer or a predicate.
1044 See Info node `(gnus)Customizing Articles' for details."
1045 :group 'gnus-article-treat
1046 :type gnus-article-treat-head-custom)
1048 (defcustom gnus-treat-date-iso8601 nil
1049 "Display the date in the ISO8601 format.
1050 Valid values are nil, t, `head', `last', an integer or a predicate.
1051 See Info node `(gnus)Customizing Articles' for details."
1053 :group 'gnus-article-treat
1054 :type gnus-article-treat-head-custom)
1056 (defcustom gnus-treat-date-user-defined nil
1057 "Display the date in a user-defined format.
1058 The format is defined by the `gnus-article-time-format' variable.
1059 Valid values are nil, t, `head', `last', an integer or a predicate.
1060 See Info node `(gnus)Customizing Articles' for details."
1061 :group 'gnus-article-treat
1062 :type gnus-article-treat-head-custom)
1064 (defcustom gnus-treat-strip-headers-in-body t
1065 "Strip the X-No-Archive header line from the beginning of the body.
1066 Valid values are nil, t, `head', `last', an integer or a predicate.
1067 See Info node `(gnus)Customizing Articles' for details."
1069 :group 'gnus-article-treat
1070 :type gnus-article-treat-custom)
1072 (defcustom gnus-treat-strip-trailing-blank-lines nil
1073 "Strip trailing blank lines.
1074 Valid values are nil, t, `head', `last', an integer or a predicate.
1075 See Info node `(gnus)Customizing Articles' for details."
1076 :group 'gnus-article-treat
1077 :type gnus-article-treat-custom)
1079 (defcustom gnus-treat-strip-leading-blank-lines nil
1080 "Strip leading blank lines.
1081 Valid values are nil, t, `head', `last', an integer or a predicate.
1082 See Info node `(gnus)Customizing Articles' for details."
1083 :group 'gnus-article-treat
1084 :type gnus-article-treat-custom)
1086 (defcustom gnus-treat-strip-multiple-blank-lines nil
1087 "Strip multiple blank lines.
1088 Valid values are nil, t, `head', `last', an integer or a predicate.
1089 See Info node `(gnus)Customizing Articles' for details."
1090 :group 'gnus-article-treat
1091 :type gnus-article-treat-custom)
1093 (defcustom gnus-treat-unfold-headers 'head
1094 "Unfold folded header lines.
1095 Valid values are nil, t, `head', `last', an integer or a predicate.
1096 See Info node `(gnus)Customizing Articles' for details."
1097 :group 'gnus-article-treat
1098 :type gnus-article-treat-custom)
1100 (defcustom gnus-treat-fold-headers nil
1102 Valid values are nil, t, `head', `last', an integer or a predicate.
1103 See Info node `(gnus)Customizing Articles' for details."
1104 :group 'gnus-article-treat
1105 :type gnus-article-treat-custom)
1107 (defcustom gnus-treat-fold-newsgroups 'head
1108 "Fold the Newsgroups and Followup-To headers.
1109 Valid values are nil, t, `head', `last', an integer or a predicate.
1110 See Info node `(gnus)Customizing Articles' for details."
1111 :group 'gnus-article-treat
1112 :type gnus-article-treat-custom)
1114 (defcustom gnus-treat-overstrike t
1115 "Treat overstrike highlighting.
1116 Valid values are nil, t, `head', `last', an integer or a predicate.
1117 See Info node `(gnus)Customizing Articles' for details."
1118 :group 'gnus-article-treat
1119 :type gnus-article-treat-custom)
1120 (put 'gnus-treat-overstrike 'highlight t)
1122 (defcustom gnus-treat-display-xface
1123 (and (or (and (fboundp 'image-type-available-p)
1124 (image-type-available-p 'xbm)
1125 (string-match "^0x" (shell-command-to-string "uncompface")))
1126 (and (featurep 'xemacs)
1128 (eq 'x-face-mule-gnus-article-display-x-face
1129 gnus-article-x-face-command))
1131 "Display X-Face headers.
1132 Valid values are nil, t, `head', `last', an integer or a predicate.
1133 See Info node `(gnus)Customizing Articles' and Info node
1134 `(gnus)X-Face' for details."
1135 :group 'gnus-article-treat
1137 :type gnus-article-treat-head-custom)
1138 (put 'gnus-treat-display-xface 'highlight t)
1140 (defcustom gnus-article-should-use-smiley-mule
1141 (not (or (featurep 'xemacs)
1142 (gnus-image-type-available-p 'xpm)
1143 (gnus-image-type-available-p 'pbm)))
1144 "If non-nil, gnus uses `smiley-mule' for displaying smileys rather than
1145 `smiley'. It defaults to t when Emacs 20 or earlier is running.
1146 `smiley-mule' is boundled in BITMAP-MULE package. You can set it to t
1147 even if you are using Emacs 21+. It has no effect on XEmacs."
1148 :group 'gnus-article-various
1150 :get (lambda (symbol)
1151 (and (default-value symbol)
1152 (not (featurep 'xemacs))
1153 (module-installed-p 'smiley-mule)
1155 :set (lambda (symbol value)
1156 (set-default symbol (and value
1157 (not (featurep 'xemacs))
1158 (module-installed-p 'smiley-mule)
1161 (defvar gnus-article-smiley-mule-loaded-p nil
1162 "Internal variable used to say whether `smiley-mule' is loaded (whether
1163 smiley functions are not overridden by `smiley').")
1165 (defcustom gnus-treat-display-grey-xface
1166 (and (string-match "^0x" (shell-command-to-string "uncompface"))
1168 "Display grey X-Face headers.
1169 Valid values are nil, t."
1170 :group 'gnus-article-treat
1173 (put 'gnus-treat-display-grey-xface 'highlight t)
1175 (defcustom gnus-treat-display-smileys
1176 (if (or (and (featurep 'xemacs)
1178 (gnus-image-type-available-p 'xpm)
1179 (gnus-image-type-available-p 'pbm)
1180 (and (not (featurep 'xemacs))
1182 (module-installed-p 'smiley-mule)))
1186 Valid values are nil, t, `head', `last', an integer or a predicate.
1187 See Info node `(gnus)Customizing Articles' and Info node
1188 `(gnus)Smileys' for details."
1189 :group 'gnus-article-treat
1191 :type gnus-article-treat-custom)
1192 (put 'gnus-treat-display-smileys 'highlight t)
1194 (defcustom gnus-treat-from-picon
1195 (if (and (gnus-image-type-available-p 'xpm)
1196 (gnus-picons-installed-p))
1198 "Display picons in the From header.
1199 Valid values are nil, t, `head', `last', an integer or a predicate.
1200 See Info node `(gnus)Customizing Articles' and Info node
1201 `(gnus)Picons' for details."
1202 :group 'gnus-article-treat
1203 :type gnus-article-treat-head-custom)
1204 (put 'gnus-treat-from-picon 'highlight t)
1206 (defcustom gnus-treat-mail-picon
1207 (if (and (gnus-image-type-available-p 'xpm)
1208 (gnus-picons-installed-p))
1210 "Display picons in To and Cc headers.
1211 Valid values are nil, t, `head', `last', an integer or a predicate.
1212 See Info node `(gnus)Customizing Articles' and Info node
1213 `(gnus)Picons' for details."
1214 :group 'gnus-article-treat
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
1227 :type gnus-article-treat-head-custom)
1228 (put 'gnus-treat-newsgroups-picon 'highlight t)
1230 (defcustom gnus-treat-body-boundary
1231 (if (or gnus-treat-newsgroups-picon
1232 gnus-treat-mail-picon
1233 gnus-treat-from-picon)
1235 "Draw a boundary at the end of the headers.
1236 Valid values are nil, t, `head', `last', an integer or a predicate.
1237 See Info node `(gnus)Customizing Articles' for details."
1239 :group 'gnus-article-treat
1240 :type gnus-article-treat-custom)
1242 (defcustom gnus-treat-capitalize-sentences nil
1243 "Capitalize sentence-starting words.
1244 Valid values are nil, t, `head', `last', an integer or a predicate.
1245 See Info node `(gnus)Customizing Articles' for details."
1247 :group 'gnus-article-treat
1248 :type gnus-article-treat-custom)
1250 (defcustom gnus-treat-fill-long-lines nil
1252 Valid values are nil, t, `head', `last', an integer or a predicate.
1253 See Info node `(gnus)Customizing Articles' for details."
1254 :group 'gnus-article-treat
1255 :type gnus-article-treat-custom)
1257 (defcustom gnus-treat-play-sounds nil
1259 Valid values are nil, t, `head', `last', an integer or a predicate.
1260 See Info node `(gnus)Customizing Articles' for details."
1262 :group 'gnus-article-treat
1263 :type gnus-article-treat-custom)
1265 (defcustom gnus-treat-decode-article-as-default-mime-charset nil
1266 "Decode an article as `default-mime-charset'. For instance, if you want to
1267 attempt to decode an article even if the value of `gnus-show-mime' is nil,
1268 you could set this variable to something like: nil for don't decode, t for
1269 decode the body, '(or header t) for the whole article, etc."
1270 :group 'gnus-article-treat
1271 :type '(radio (const :tag "Off" nil)
1272 (const :tag "Decode body" t)
1273 (const :tag "Decode all" (or head t))))
1275 (defcustom gnus-treat-translate nil
1276 "Translate articles from one language to another.
1277 Valid values are nil, t, `head', `last', an integer or a predicate.
1278 See Info node `(gnus)Customizing Articles' for details."
1280 :group 'gnus-article-treat
1281 :type gnus-article-treat-custom)
1283 (defcustom gnus-treat-x-pgp-sig nil
1285 To automatically treat X-PGP-Sig, set it to head.
1286 Valid values are nil, t, `head', `last', an integer or a predicate.
1287 See Info node `(gnus)Customizing Articles' for details."
1288 :group 'gnus-article-treat
1289 :group 'mime-security
1290 :type gnus-article-treat-custom)
1292 (defvar gnus-article-encrypt-protocol-alist
1293 '(("PGP" . mml2015-self-encrypt)))
1295 ;; Set to nil if more than one protocol added to
1296 ;; gnus-article-encrypt-protocol-alist.
1297 (defcustom gnus-article-encrypt-protocol "PGP"
1298 "The protocol used for encrypt articles.
1299 It is a string, such as \"PGP\". If nil, ask user."
1301 :group 'mime-security)
1303 (defcustom gnus-article-wash-function
1304 (cond ((locate-library "w3")
1305 'gnus-article-wash-html-with-w3)
1306 ((locate-library "w3m")
1307 'gnus-article-wash-html-with-w3m))
1308 "Function used for converting HTML into text."
1309 :type '(radio (function-item gnus-article-wash-html-with-w3)
1310 (function-item gnus-article-wash-html-with-w3m))
1311 :group 'gnus-article)
1313 ;;; Internal variables
1315 (defvar gnus-english-month-names
1316 '("January" "February" "March" "April" "May" "June" "July" "August"
1317 "September" "October" "November" "December"))
1319 (defvar article-goto-body-goes-to-point-min-p nil)
1320 (defvar gnus-article-wash-types nil)
1321 (defvar gnus-article-emphasis-alist nil)
1322 (defvar gnus-article-image-alist nil)
1324 (defvar gnus-article-mime-handle-alist-1 nil)
1325 (defvar gnus-treatment-function-alist
1326 '((gnus-treat-decode-article-as-default-mime-charset
1327 gnus-article-decode-article-as-default-mime-charset)
1328 (gnus-treat-x-pgp-sig gnus-article-verify-x-pgp-sig)
1329 (gnus-treat-strip-banner gnus-article-strip-banner)
1330 (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
1331 (gnus-treat-buttonize gnus-article-add-buttons)
1332 (gnus-treat-fill-article gnus-article-fill-cited-article)
1333 (gnus-treat-fill-long-lines gnus-article-fill-long-lines)
1334 (gnus-treat-strip-cr gnus-article-remove-cr)
1335 (gnus-treat-unsplit-urls gnus-article-unsplit-urls)
1336 (gnus-treat-date-ut gnus-article-date-ut)
1337 (gnus-treat-date-local gnus-article-date-local)
1338 (gnus-treat-date-english gnus-article-date-english)
1339 (gnus-treat-date-lapsed gnus-article-date-lapsed)
1340 (gnus-treat-date-original gnus-article-date-original)
1341 (gnus-treat-date-user-defined gnus-article-date-user)
1342 (gnus-treat-date-iso8601 gnus-article-date-iso8601)
1343 (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
1344 (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
1345 (gnus-treat-hide-signature gnus-article-hide-signature)
1346 (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
1347 (gnus-treat-leading-whitespace gnus-article-remove-leading-whitespace)
1348 (gnus-treat-strip-pgp gnus-article-hide-pgp)
1349 (gnus-treat-strip-pem gnus-article-hide-pem)
1350 (gnus-treat-from-picon gnus-treat-from-picon)
1351 (gnus-treat-mail-picon gnus-treat-mail-picon)
1352 (gnus-treat-newsgroups-picon gnus-treat-newsgroups-picon)
1353 (gnus-treat-highlight-headers gnus-article-highlight-headers)
1354 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1355 (gnus-treat-strip-trailing-blank-lines
1356 gnus-article-remove-trailing-blank-lines)
1357 (gnus-treat-strip-leading-blank-lines
1358 gnus-article-strip-leading-blank-lines)
1359 (gnus-treat-strip-multiple-blank-lines
1360 gnus-article-strip-multiple-blank-lines)
1361 (gnus-treat-overstrike gnus-article-treat-overstrike)
1362 (gnus-treat-unfold-headers gnus-article-treat-unfold-headers)
1363 (gnus-treat-fold-headers gnus-article-treat-fold-headers)
1364 ;; Displaying X-Face should be done after unfolding headers
1365 ;; to protect bitmap lines.
1366 (gnus-treat-display-xface gnus-article-display-x-face)
1367 (gnus-treat-fold-newsgroups gnus-article-treat-fold-newsgroups)
1368 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
1369 (gnus-treat-display-smileys gnus-treat-smiley)
1370 (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
1371 (gnus-treat-emphasize gnus-article-emphasize)
1372 (gnus-treat-hide-citation gnus-article-hide-citation)
1373 (gnus-treat-hide-citation-maybe gnus-article-hide-citation-maybe)
1374 (gnus-treat-highlight-citation gnus-article-highlight-citation)
1375 (gnus-treat-body-boundary gnus-article-treat-body-boundary)
1376 (gnus-treat-play-sounds gnus-earcon-display)))
1378 (defvar gnus-article-mime-handle-alist nil)
1379 (defvar article-lapsed-timer nil)
1380 (defvar gnus-article-current-summary nil)
1382 (defvar gnus-article-mode-syntax-table
1383 (let ((table (copy-syntax-table text-mode-syntax-table)))
1384 ;; This causes the citation match run O(2^n).
1385 ;; (modify-syntax-entry ?- "w" table)
1386 (modify-syntax-entry ?> ")" table)
1387 (modify-syntax-entry ?< "(" table)
1389 "Syntax table used in article mode buffers.
1390 Initialized from `text-mode-syntax-table.")
1392 (defvar gnus-save-article-buffer nil)
1394 (defvar gnus-article-mode-line-format-alist
1395 (nconc '((?w (gnus-article-wash-status) ?s)
1396 (?m (gnus-article-mime-part-status) ?s))
1397 gnus-summary-mode-line-format-alist))
1399 (defvar gnus-number-of-articles-to-be-saved nil)
1401 (defvar gnus-inhibit-hiding nil)
1403 ;;; Macros for dealing with the article buffer.
1405 (defmacro gnus-with-article-headers (&rest forms)
1407 (set-buffer gnus-article-buffer)
1409 (let ((buffer-read-only nil)
1410 (inhibit-point-motion-hooks t)
1411 (case-fold-search t))
1412 (article-narrow-to-head)
1415 (put 'gnus-with-article-headers 'lisp-indent-function 0)
1416 (put 'gnus-with-article-headers 'edebug-form-spec '(body))
1418 (defmacro gnus-with-article-buffer (&rest forms)
1420 (set-buffer gnus-article-buffer)
1421 (let ((buffer-read-only nil))
1424 (put 'gnus-with-article-buffer 'lisp-indent-function 0)
1425 (put 'gnus-with-article-buffer 'edebug-form-spec '(body))
1427 (defun gnus-article-goto-header (header)
1428 "Go to HEADER, which is a regular expression."
1429 (re-search-forward (concat "^\\(" header "\\):") nil t))
1431 (defsubst gnus-article-hide-text (b e props)
1432 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
1433 (gnus-add-text-properties-when 'article-type nil b e props)
1434 (when (memq 'intangible props)
1436 (max (1- b) (point-min))
1437 b 'intangible (cddr (memq 'intangible props)))))
1439 (defsubst gnus-article-unhide-text (b e)
1440 "Remove hidden text properties from region between B and E."
1441 (remove-text-properties b e gnus-hidden-properties)
1442 (when (memq 'intangible gnus-hidden-properties)
1443 (put-text-property (max (1- b) (point-min))
1444 b 'intangible nil)))
1446 (defun gnus-article-hide-text-type (b e type)
1447 "Hide text of TYPE between B and E."
1448 (gnus-add-wash-type type)
1449 (gnus-article-hide-text
1450 b e (cons 'article-type (cons type gnus-hidden-properties))))
1452 (defun gnus-article-unhide-text-type (b e type)
1453 "Unhide text of TYPE between B and E."
1454 (gnus-delete-wash-type type)
1455 (remove-text-properties
1456 b e (cons 'article-type (cons type gnus-hidden-properties)))
1457 (when (memq 'intangible gnus-hidden-properties)
1458 (put-text-property (max (1- b) (point-min))
1459 b 'intangible nil)))
1461 (defun gnus-article-hide-text-of-type (type)
1462 "Hide text of TYPE in the current buffer."
1464 (let ((b (point-min))
1466 (while (setq b (text-property-any b e 'article-type type))
1467 (add-text-properties b (incf b) gnus-hidden-properties)))))
1469 (defun gnus-article-delete-text-of-type (type)
1470 "Delete text of TYPE in the current buffer."
1472 (let ((b (point-min)))
1473 (while (setq b (text-property-any b (point-max) 'article-type type))
1475 b (or (text-property-not-all b (point-max) 'article-type type)
1478 (defun gnus-article-delete-invisible-text ()
1479 "Delete all invisible text in the current buffer."
1481 (let ((b (point-min)))
1482 (while (setq b (text-property-any b (point-max) 'invisible t))
1484 b (or (text-property-not-all b (point-max) 'invisible t)
1487 (defun gnus-article-text-type-exists-p (type)
1488 "Say whether any text of type TYPE exists in the buffer."
1489 (text-property-any (point-min) (point-max) 'article-type type))
1491 (defsubst gnus-article-header-rank ()
1492 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1493 (let ((list gnus-sorted-header-list)
1496 (when (looking-at (car list))
1498 (setq list (cdr list))
1502 (defun article-hide-headers (&optional arg delete)
1503 "Hide unwanted headers and possibly sort them as well."
1504 (interactive (gnus-article-hidden-arg))
1505 ;; Lars said that this function might be inhibited.
1506 (if (gnus-article-check-hidden-text 'headers arg)
1508 ;; Show boring headers as well.
1509 (gnus-article-show-hidden-text 'boring-headers)
1510 (when (eq 1 (point-min))
1511 (set-window-start (get-buffer-window (current-buffer)) 1)))
1512 (unless gnus-inhibit-hiding
1515 (let ((inhibit-read-only t)
1516 (case-fold-search t)
1517 (max (1+ (length gnus-sorted-header-list)))
1518 (ignored (when (not gnus-visible-headers)
1519 (cond ((stringp gnus-ignored-headers)
1520 gnus-ignored-headers)
1521 ((listp gnus-ignored-headers)
1522 (mapconcat 'identity gnus-ignored-headers
1525 (cond ((stringp gnus-visible-headers)
1526 gnus-visible-headers)
1527 ((and gnus-visible-headers
1528 (listp gnus-visible-headers))
1529 (mapconcat 'identity gnus-visible-headers "\\|"))))
1530 (inhibit-point-motion-hooks t)
1532 ;; First we narrow to just the headers.
1533 (article-narrow-to-head)
1534 ;; Hide any "From " lines at the beginning of (mail) articles.
1535 (while (looking-at "From ")
1539 (delete-region (point-min) (point))
1540 (gnus-article-hide-text (point-min) (point)
1541 (nconc (list 'article-type 'headers)
1542 gnus-hidden-properties))))
1543 ;; Then treat the rest of the header lines.
1544 ;; Then we use the two regular expressions
1545 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1546 ;; select which header lines is to remain visible in the
1548 (while (re-search-forward "^[^ \t:]*:" nil t)
1550 ;; Mark the rank of the header.
1552 (point) (1+ (point)) 'message-rank
1553 (if (or (and visible (looking-at visible))
1555 (not (looking-at ignored))))
1556 (gnus-article-header-rank)
1559 (message-sort-headers-1)
1560 (when (setq beg (text-property-any
1561 (point-min) (point-max) 'message-rank (+ 2 max)))
1562 ;; We delete or make invisible the unwanted headers.
1563 (gnus-add-wash-type 'headers)
1566 (add-text-properties
1567 (point-min) (+ 5 (point-min))
1568 '(article-type headers dummy-invisible t))
1569 (delete-region beg (point-max)))
1570 (gnus-article-hide-text-type beg (point-max) 'headers)))))))))
1572 (defun article-hide-boring-headers (&optional arg)
1573 "Toggle hiding of headers that aren't very interesting.
1574 If given a negative prefix, always show; if given a positive prefix,
1576 (interactive (gnus-article-hidden-arg))
1577 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1578 (not gnus-show-all-headers))
1581 (let ((buffer-read-only nil)
1582 (list gnus-boring-article-headers)
1583 (inhibit-point-motion-hooks t)
1585 (article-narrow-to-head)
1587 (setq elem (pop list))
1588 (goto-char (point-min))
1590 ;; Hide empty headers.
1592 (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1594 (gnus-article-hide-text-type
1595 (progn (beginning-of-line) (point))
1598 (if (re-search-forward "^[^ \t]" nil t)
1602 ;; Hide boring Newsgroups header.
1603 ((eq elem 'newsgroups)
1604 (when (gnus-string-equal
1605 (gnus-fetch-field "newsgroups")
1606 (gnus-group-real-name
1607 (if (boundp 'gnus-newsgroup-name)
1610 (gnus-article-hide-header "newsgroups")))
1611 ((eq elem 'to-address)
1612 (let ((to (message-fetch-field "to"))
1614 (gnus-parameter-to-address
1615 (if (boundp 'gnus-newsgroup-name)
1616 gnus-newsgroup-name ""))))
1617 (when (and to to-address
1620 ;; only one address in To
1621 (nth 1 (mail-extract-address-components to))
1623 (gnus-article-hide-header "to"))))
1624 ((eq elem 'followup-to)
1625 (when (gnus-string-equal
1626 (message-fetch-field "followup-to")
1627 (message-fetch-field "newsgroups"))
1628 (gnus-article-hide-header "followup-to")))
1629 ((eq elem 'reply-to)
1630 (let ((from (message-fetch-field "from"))
1631 (reply-to (message-fetch-field "reply-to")))
1636 (nth 1 (mail-extract-address-components from))
1637 (nth 1 (mail-extract-address-components reply-to)))))
1638 (gnus-article-hide-header "reply-to"))))
1640 (let ((date (message-fetch-field "date")))
1642 (< (days-between (current-time-string) date)
1644 (gnus-article-hide-header "date"))))
1646 (let ((to (message-fetch-field "to"))
1647 (cc (message-fetch-field "cc")))
1648 (when (> (length to) 1024)
1649 (gnus-article-hide-header "to"))
1650 (when (> (length cc) 1024)
1651 (gnus-article-hide-header "cc"))))
1655 (goto-char (point-min))
1656 (while (re-search-forward "^to:" nil t)
1657 (setq to-count (1+ to-count)))
1658 (when (> to-count 1)
1659 (while (> to-count 0)
1660 (goto-char (point-min))
1662 (re-search-forward "^to:" nil nil to-count)
1664 (narrow-to-region (point) (point-max))
1665 (gnus-article-hide-header "to"))
1666 (setq to-count (1- to-count))))
1667 (goto-char (point-min))
1668 (while (re-search-forward "^cc:" nil t)
1669 (setq cc-count (1+ cc-count)))
1670 (when (> cc-count 1)
1671 (while (> cc-count 0)
1672 (goto-char (point-min))
1674 (re-search-forward "^cc:" nil nil cc-count)
1676 (narrow-to-region (point) (point-max))
1677 (gnus-article-hide-header "cc"))
1678 (setq cc-count (1- cc-count)))))))))))))
1680 (defun gnus-article-hide-header (header)
1682 (goto-char (point-min))
1683 (when (re-search-forward (concat "^" header ":") nil t)
1684 (gnus-article-hide-text-type
1685 (progn (beginning-of-line) (point))
1688 (if (re-search-forward "^[^ \t]" nil t)
1693 (defun article-toggle-headers (&optional arg)
1694 "Toggle hiding of headers. If given a negative prefix, always show;
1695 if given a positive prefix, always hide."
1696 (interactive (gnus-article-hidden-arg))
1697 (let ((force (when (numberp arg)
1698 (cond ((> arg 0) 'always-hide)
1699 ((< arg 0) 'always-show))))
1700 (window (get-buffer-window gnus-article-buffer))
1701 (header-end (point-min))
1702 header-start field-end field-start
1703 (inhibit-point-motion-hooks t)
1704 (inhibit-read-only t))
1707 (while (and (setq header-start
1708 (text-property-any header-end (point-max)
1709 'article-treated-header t))
1711 (text-property-not-all header-start (point-max)
1712 'article-treated-header t)))
1713 (setq field-end header-start)
1715 (;; Hide exposed invisible fields.
1716 (and (not (eq 'always-show force))
1718 (text-property-any field-end header-end
1719 'exposed-invisible-field t)))
1720 (while (and field-start
1721 (setq field-end (text-property-not-all
1722 field-start header-end
1723 'exposed-invisible-field t)))
1724 (add-text-properties field-start field-end gnus-hidden-properties)
1725 (setq field-start (text-property-any field-end header-end
1726 'exposed-invisible-field t)))
1727 (put-text-property header-start header-end
1728 'exposed-invisible-field nil))
1729 (;; Expose invisible fields.
1730 (and (not (eq 'always-hide force))
1732 (text-property-any field-end header-end 'invisible t)))
1733 (while (and field-start
1734 (setq field-end (text-property-not-all
1735 field-start header-end
1737 ;; If the invisible text is not terminated with newline, we
1738 ;; won't expose it. Because it may be created by x-face-mule.
1739 ;; BTW, XEmacs sometimes fail in putting an invisible text
1740 ;; property with `gnus-article-hide-text' (really?). In that
1741 ;; case, the invisible text might be started from the middle of
1742 ;; a line, so we will expose the sort of thing.
1743 (when (or (not (or (eq header-start field-start)
1744 (eq ?\n (char-before field-start))))
1745 (eq ?\n (char-before field-end))
1746 ;; Expose a boundary line anyway.
1749 (buffer-substring (max (- field-end 13) header-start)
1751 (remove-text-properties field-start field-end
1752 gnus-hidden-properties)
1753 (put-text-property field-start field-end
1754 'exposed-invisible-field t))
1755 (setq field-start (text-property-any field-end header-end
1758 (not (eq 'always-show force))
1759 (narrow-to-region header-start header-end)
1760 (article-hide-headers)
1761 ;; Re-display X-Face image under XEmacs.
1762 (when (and (featurep 'xemacs)
1763 (gnus-functionp gnus-article-x-face-command))
1764 (let ((func (cadr (assq 'gnus-treat-display-xface
1765 gnus-treatment-function-alist)))
1767 (when (and (not gnus-inhibit-treatment)
1769 (gnus-treat-predicate gnus-treat-display-xface))
1771 (put-text-property header-start header-end 'read-only nil))))
1774 (goto-char (point-min))
1776 (set-window-start window (point-min))))))
1778 (defvar gnus-article-normalized-header-length 40
1779 "Length of normalized headers.")
1781 (defun article-normalize-headers ()
1782 "Make all header lines 40 characters long."
1784 (let ((buffer-read-only nil)
1788 (article-narrow-to-head)
1791 ((< (setq column (- (gnus-point-at-eol) (point)))
1792 gnus-article-normalized-header-length)
1794 (insert (make-string
1795 (- gnus-article-normalized-header-length column)
1797 ((> column gnus-article-normalized-header-length)
1798 (gnus-put-text-property
1800 (forward-char gnus-article-normalized-header-length)
1807 (forward-line 1))))))
1809 (defun article-treat-dumbquotes ()
1810 "Translate M****s*** sm*rtq**t*s into proper text.
1811 Note that this function guesses whether a character is a sm*rtq**t* or
1812 not, so it should only be used interactively.
1814 Sm*rtq**t*s are M****s***'s unilateral extension to the character map
1815 in an attempt to provide more quoting characters. If you see
1816 something like \\222 or \\264 where you're expecting some kind of
1817 apostrophe or quotation mark, then try this wash."
1819 (article-translate-strings gnus-article-dumbquotes-map))
1821 (defun article-translate-characters (from to)
1822 "Translate all characters in the body of the article according to FROM and TO.
1823 FROM is a string of characters to translate from; to is a string of
1824 characters to translate to."
1826 (when (article-goto-body)
1827 (let ((buffer-read-only nil)
1828 (x (make-string 225 ?x))
1830 (while (< (incf i) (length x))
1833 (while (< i (length from))
1834 (aset x (aref from i) (aref to i))
1836 (translate-region (point) (point-max) x)))))
1838 (defun article-translate-strings (map)
1839 "Translate all string in the body of the article according to MAP.
1840 MAP is an alist where the elements are on the form (\"from\" \"to\")."
1842 (when (article-goto-body)
1843 (let ((buffer-read-only nil)
1845 (while (setq elem (pop map))
1847 (while (search-forward (car elem) nil t)
1848 (replace-match (cadr elem)))))))))
1850 (defun article-treat-overstrike ()
1851 "Translate overstrikes into bold text."
1854 (when (article-goto-body)
1855 (let ((buffer-read-only nil))
1856 (while (search-forward "\b" nil t)
1857 (let ((next (char-after))
1861 previous (char-after))
1865 ;; We do the boldification/underlining by hiding the
1866 ;; overstrikes and putting the proper text property
1870 (gnus-article-hide-text-type start (point) 'overstrike)
1871 (put-text-property (point) end 'face 'bold))
1873 (gnus-article-hide-text-type
1874 (1- (point)) (1+ (point)) 'overstrike)
1876 start (1- (point)) 'face 'underline))
1878 (gnus-article-hide-text-type start (point) 'overstrike)
1880 (point) end 'face 'underline)))))))))
1882 (defun gnus-article-treat-unfold-headers ()
1883 "Unfold folded message headers.
1884 Only the headers that fit into the current window width will be
1887 (gnus-with-article-headers
1891 (mail-header-narrow-to-field)
1892 (let ((header (buffer-substring (point-min) (point-max))))
1895 (goto-char (point-min))
1896 (while (re-search-forward "\n[\t ]" nil t)
1897 (replace-match " " t t)))
1898 (setq length (- (point-max) (point-min) 1)))
1899 (when (< length (window-width))
1900 (while (re-search-forward "\n[\t ]" nil t)
1901 (replace-match " " t t)))
1902 (goto-char (point-max)))))))
1904 (defun gnus-article-treat-fold-headers ()
1905 "Fold message headers."
1907 (gnus-with-article-headers
1910 (mail-header-narrow-to-field)
1911 (mail-header-fold-field)
1912 (goto-char (point-max))))))
1914 (defun gnus-treat-smiley ()
1915 "Toggle display of textual emoticons (\"smileys\") as small graphical icons."
1917 (unless (featurep 'xemacs)
1918 (when (and (>= emacs-major-version 21)
1919 (not gnus-article-should-use-smiley-mule)
1920 gnus-article-smiley-mule-loaded-p)
1921 (load "smiley" nil t)
1922 (setq gnus-article-smiley-mule-loaded-p nil))
1923 (when (and gnus-article-should-use-smiley-mule
1924 (not gnus-article-smiley-mule-loaded-p))
1925 (load "smiley-mule" nil t)
1926 (setq gnus-article-smiley-mule-loaded-p t)))
1927 (gnus-with-article-buffer
1928 (if (memq 'smiley gnus-article-wash-types)
1929 (gnus-delete-images 'smiley)
1931 (let ((images (smiley-region (point) (point-max))))
1933 (gnus-add-wash-type 'smiley)
1934 (dolist (image images)
1935 (gnus-add-image 'smiley image)))))))
1937 (defun gnus-article-remove-images ()
1938 "Remove all images from the article buffer."
1940 (gnus-with-article-buffer
1941 (dolist (elem gnus-article-image-alist)
1942 (gnus-delete-images (car elem)))))
1944 (defun gnus-article-treat-fold-newsgroups ()
1945 "Unfold folded message headers.
1946 Only the headers that fit into the current window width will be
1949 (gnus-with-article-headers
1950 (while (gnus-article-goto-header "newsgroups\\|followup-to")
1952 (mail-header-narrow-to-field)
1953 (while (re-search-forward ", *" nil t)
1954 (replace-match ", " t t))
1955 (mail-header-fold-field)
1956 (goto-char (point-max))))))
1958 (defun gnus-article-treat-body-boundary ()
1959 "Place a boundary line at the end of the headers."
1961 (when (and gnus-body-boundary-delimiter
1962 (> (length gnus-body-boundary-delimiter) 0))
1963 (gnus-with-article-headers
1964 (goto-char (point-max))
1965 (let ((start (point)))
1966 (insert "X-Boundary: ")
1967 (gnus-add-text-properties start (point) '(invisible t intangible t))
1969 (while (>= (1- (window-width)) (length str))
1970 (setq str (concat str gnus-body-boundary-delimiter)))
1971 (substring str 0 (1- (window-width))))
1973 (gnus-add-text-properties start (point) '(gnus-decoration 'header))))))
1975 (defun article-fill-long-lines ()
1976 "Fill lines that are wider than the window width."
1979 (let ((buffer-read-only nil)
1980 (width (window-width (get-buffer-window (current-buffer)))))
1983 (let ((adaptive-fill-mode nil)) ;Why? -sm
1986 (when (>= (current-column) (min fill-column width))
1987 (narrow-to-region (point) (gnus-point-at-bol))
1988 (fill-paragraph nil)
1989 (goto-char (point-max))
1991 (forward-line 1)))))))
1993 (defun article-capitalize-sentences ()
1994 "Capitalize the first word in each sentence."
1997 (let ((buffer-read-only nil)
1998 (paragraph-start "^[\n\^L]"))
2002 (forward-sentence)))))
2004 (defun article-remove-cr ()
2005 "Remove trailing CRs and then translate remaining CRs into LFs."
2008 (let ((buffer-read-only nil))
2009 (goto-char (point-min))
2010 (while (re-search-forward "\r+$" nil t)
2011 (replace-match "" t t))
2012 (goto-char (point-min))
2013 (while (search-forward "\r" nil t)
2014 (replace-match "\n" t t)))))
2016 (defun article-remove-trailing-blank-lines ()
2017 "Remove all trailing blank lines from the article."
2020 (let ((buffer-read-only nil))
2021 (goto-char (point-max))
2025 (while (and (not (bobp))
2026 (looking-at "^[ \t]*$")
2027 (not (gnus-annotation-in-region-p
2028 (point) (gnus-point-at-eol))))
2033 (defun article-display-x-face (&optional force)
2034 "Look for an X-Face header and display it if present."
2035 (interactive (list 'force))
2036 (let ((wash-face-p buffer-read-only)) ;; When type `W f'
2037 (gnus-with-article-headers
2038 ;; Delete the old process, if any.
2039 (when (process-status "article-x-face")
2040 (delete-process "article-x-face"))
2041 (if (memq 'xface gnus-article-wash-types)
2042 ;; We have already displayed X-Faces, so we remove them
2044 (gnus-delete-images 'xface)
2046 (let (x-faces from face grey)
2048 (when (and wash-face-p
2050 (goto-char (point-min))
2051 (not (re-search-forward
2052 "^X-Face\\(-[0-9]+\\)?:[\t ]*" nil t)))
2053 (gnus-buffer-live-p gnus-original-article-buffer))
2054 ;; If type `W f', use gnus-original-article-buffer,
2055 ;; otherwise use the current buffer because displaying
2056 ;; RFC822 parts calls this function too.
2057 (set-buffer gnus-original-article-buffer))
2059 (mail-narrow-to-head)
2061 (if gnus-treat-display-grey-xface
2062 "x-face\\(-[0-9]+\\)?"
2064 (while (gnus-article-goto-header regexp)
2065 (when (match-beginning 2)
2067 (push (mail-header-field-value) x-faces)))
2068 (setq from (message-fetch-field "from"))))
2070 (let ((xpm (gnus-convert-gray-x-face-to-xpm x-faces))
2073 (setq image (gnus-create-image xpm 'xpm t))
2074 (gnus-article-goto-header "from")
2076 (insert "From: [no `from' set]\n")
2078 (gnus-add-wash-type 'xface)
2079 (gnus-add-image 'xface image)
2080 (gnus-put-image image)))
2081 ;; Sending multiple EOFs to xv doesn't work, so we only do a
2082 ;; single external face.
2083 (when (stringp gnus-article-x-face-command)
2084 (setq x-faces (list (car x-faces))))
2085 (while (and (setq face (pop x-faces))
2086 gnus-article-x-face-command
2088 ;; Check whether this face is censored.
2089 (not gnus-article-x-face-too-ugly)
2090 (and gnus-article-x-face-too-ugly from
2091 (not (string-match gnus-article-x-face-too-ugly
2093 ;; We display the face.
2094 (if (symbolp gnus-article-x-face-command)
2095 ;; The command is a lisp function, so we call it.
2096 (if (gnus-functionp gnus-article-x-face-command)
2097 (funcall gnus-article-x-face-command face)
2098 (error "%s is not a function" gnus-article-x-face-command))
2099 ;; The command is a string, so we interpret the command
2100 ;; as a, well, command, and fork it off.
2101 (let ((process-connection-type nil))
2102 (process-kill-without-query
2104 "article-x-face" nil shell-file-name shell-command-switch
2105 gnus-article-x-face-command))
2108 (process-send-region "article-x-face"
2109 (point-min) (point-max)))
2110 (process-send-eof "article-x-face"))))))))))
2112 (defun article-decode-mime-words ()
2113 "Decode all MIME-encoded words in the article."
2116 (set-buffer gnus-article-buffer)
2117 (let ((inhibit-point-motion-hooks t)
2119 (mail-parse-charset gnus-newsgroup-charset)
2120 (mail-parse-ignored-charsets
2121 (save-excursion (set-buffer gnus-summary-buffer)
2122 gnus-newsgroup-ignored-charsets)))
2123 (mail-decode-encoded-word-region (point-min) (point-max)))))
2125 (defun article-decode-charset (&optional prompt)
2126 "Decode charset-encoded text in the article.
2127 If PROMPT (the prefix), prompt for a coding system to use."
2129 (let ((inhibit-point-motion-hooks t) (case-fold-search t)
2131 (mail-parse-charset gnus-newsgroup-charset)
2132 (mail-parse-ignored-charsets
2133 (save-excursion (condition-case nil
2134 (set-buffer gnus-summary-buffer)
2136 gnus-newsgroup-ignored-charsets))
2137 ct cte ctl charset format)
2140 (article-narrow-to-head)
2141 (setq ct (message-fetch-field "Content-Type" t)
2142 cte (message-fetch-field "Content-Transfer-Encoding" t)
2143 ctl (and ct (ignore-errors
2144 (mail-header-parse-content-type ct)))
2147 (mm-read-coding-system "Charset to decode: "))
2149 (mail-content-type-get ctl 'charset)))
2150 format (and ctl (mail-content-type-get ctl 'format)))
2152 (setq cte (mail-header-strip cte)))
2153 (if (and ctl (not (string-match "/" (car ctl))))
2155 (goto-char (point-max)))
2158 (narrow-to-region (point) (point-max))
2159 (when (and (eq mail-parse-charset 'gnus-decoded)
2160 (eq (mm-body-7-or-8) '8bit))
2161 ;; The text code could have been decoded.
2162 (setq charset mail-parse-charset))
2163 (when (and (or (not ctl)
2164 (equal (car ctl) "text/plain"))
2165 (not format)) ;; article with format will decode later.
2167 charset (and cte (intern (downcase
2168 (gnus-strip-whitespace cte))))
2171 (defun article-decode-encoded-words ()
2172 "Remove encoded-word encoding from headers."
2173 (let (buffer-read-only)
2174 (let ((charset (save-excursion
2175 (set-buffer gnus-summary-buffer)
2176 default-mime-charset)))
2177 (mime-decode-header-in-buffer charset))))
2179 (defun article-decode-group-name ()
2180 "Decode group names in `Newsgroups:'."
2181 (let ((inhibit-point-motion-hooks t)
2183 (method (gnus-find-method-for-group gnus-newsgroup-name)))
2184 (when (and (or gnus-group-name-charset-method-alist
2185 gnus-group-name-charset-group-alist)
2186 (gnus-buffer-live-p gnus-original-article-buffer))
2187 (when (nnmail-fetch-field "Newsgroups")
2188 (nnheader-replace-header "Newsgroups"
2189 (gnus-decode-newsgroups
2190 (with-current-buffer
2191 gnus-original-article-buffer
2192 (nnmail-fetch-field "Newsgroups"))
2193 gnus-newsgroup-name method)))
2194 (when (nnmail-fetch-field "Followup-To")
2195 (nnheader-replace-header "Followup-To"
2196 (gnus-decode-newsgroups
2197 (with-current-buffer
2198 gnus-original-article-buffer
2199 (nnmail-fetch-field "Followup-To"))
2200 gnus-newsgroup-name method))))))
2202 (defun article-de-quoted-unreadable (&optional force read-charset)
2203 "Translate a quoted-printable-encoded article.
2204 If FORCE, decode the article whether it is marked as quoted-printable
2206 If READ-CHARSET, ask for a coding system."
2207 (interactive (list 'force current-prefix-arg))
2209 (let ((buffer-read-only nil) type charset)
2210 (if (gnus-buffer-live-p gnus-original-article-buffer)
2211 (with-current-buffer gnus-original-article-buffer
2213 (gnus-fetch-field "content-transfer-encoding"))
2214 (let* ((ct (gnus-fetch-field "content-type"))
2217 (mail-header-parse-content-type ct)))))
2218 (setq charset (and ctl
2219 (mail-content-type-get ctl 'charset)))
2220 (if (stringp charset)
2221 (setq charset (intern (downcase charset)))))))
2223 (setq charset (mm-read-coding-system "Charset: " charset)))
2225 (setq charset gnus-newsgroup-charset))
2227 (and type (let ((case-fold-search t))
2228 (string-match "quoted-printable" type))))
2230 (quoted-printable-decode-region
2231 (point) (point-max) (mm-charset-to-coding-system charset))))))
2233 (defun article-de-base64-unreadable (&optional force read-charset)
2234 "Translate a base64 article.
2235 If FORCE, decode the article whether it is marked as base64 not.
2236 If READ-CHARSET, ask for a coding system."
2237 (interactive (list 'force current-prefix-arg))
2239 (let ((buffer-read-only nil) type charset)
2240 (if (gnus-buffer-live-p gnus-original-article-buffer)
2241 (with-current-buffer gnus-original-article-buffer
2243 (gnus-fetch-field "content-transfer-encoding"))
2244 (let* ((ct (gnus-fetch-field "content-type"))
2247 (mail-header-parse-content-type ct)))))
2248 (setq charset (and ctl
2249 (mail-content-type-get ctl 'charset)))
2250 (if (stringp charset)
2251 (setq charset (intern (downcase charset)))))))
2253 (setq charset (mm-read-coding-system "Charset: " charset)))
2255 (setq charset gnus-newsgroup-charset))
2257 (and type (let ((case-fold-search t))
2258 (string-match "base64" type))))
2261 (narrow-to-region (point) (point-max))
2262 (base64-decode-region (point-min) (point-max))
2263 (mm-decode-coding-region
2264 (point-min) (point-max) (mm-charset-to-coding-system charset)))))))
2269 (defun article-decode-HZ ()
2270 "Translate a HZ-encoded article."
2274 (let ((buffer-read-only nil))
2275 (rfc1843-decode-region (point-min) (point-max)))))
2277 (defun article-unsplit-urls ()
2278 "Remove the newlines that some other mailers insert into URLs."
2281 (let ((buffer-read-only nil))
2282 (goto-char (point-min))
2283 (while (re-search-forward
2284 "^\\(\\(https?\\|ftp\\)://\\S-+\\)\n\\(\\S-+\\)" nil t)
2285 (replace-match "\\1\\3" t)))))
2287 (defun article-wash-html (&optional read-charset)
2288 "Format an html article.
2289 If READ-CHARSET, ask for a coding system."
2292 (let ((buffer-read-only nil)
2294 (if (gnus-buffer-live-p gnus-original-article-buffer)
2295 (with-current-buffer gnus-original-article-buffer
2296 (let* ((ct (gnus-fetch-field "content-type"))
2299 (mail-header-parse-content-type ct)))))
2300 (setq charset (and ctl
2301 (mail-content-type-get ctl 'charset)))
2302 (if (stringp charset)
2303 (setq charset (intern (downcase charset)))))))
2305 (setq charset (mm-read-coding-system "Charset: " charset)))
2307 (setq charset gnus-newsgroup-charset))
2309 (save-window-excursion
2311 (narrow-to-region (point) (point-max))
2312 (funcall gnus-article-wash-function))))))
2314 (defun gnus-article-wash-html-with-w3 ()
2315 "Wash the current buffer with w3."
2317 (let ((w3-strict-width (window-width))
2318 (url-standalone-mode t)
2319 (url-gateway-unplugged t)
2320 (w3-honor-stylesheets nil)
2321 (w3-delay-image-loads t))
2323 (w3-region (point-min) (point-max))
2326 (defun gnus-article-wash-html-with-w3m ()
2327 "Wash the current buffer with emacs-w3m."
2330 (narrow-to-region (point) (point-max))
2331 (let ((w3m-safe-url-regexp (if mm-inline-text-html-with-images
2334 (w3m-display-inline-images mm-inline-text-html-with-images)
2335 w3m-force-redisplay)
2336 (w3m-region (point-min) (point-max)))
2337 (when mm-inline-text-html-with-w3m-keymap
2338 (add-text-properties
2339 (point-min) (point-max)
2340 (append '(mm-inline-text-html-with-w3m t)
2341 (gnus-local-map-property mm-w3m-mode-map))))))
2343 (defun article-hide-list-identifiers ()
2344 "Remove list identifies from the Subject header.
2345 The `gnus-list-identifiers' variable specifies what to do."
2347 (let ((inhibit-point-motion-hooks t)
2348 (regexp (if (consp gnus-list-identifiers)
2349 (mapconcat 'identity gnus-list-identifiers " *\\|")
2350 gnus-list-identifiers))
2355 (article-narrow-to-head)
2356 (goto-char (point-min))
2357 (while (re-search-forward
2358 (concat "^Subject: +\\(R[Ee]: +\\)*\\(" regexp " *\\)")
2360 (delete-region (match-beginning 2) (match-end 0))
2361 (beginning-of-line))
2362 (when (re-search-forward
2363 "^Subject: +\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" nil t)
2364 (delete-region (match-beginning 1) (match-end 1))))))))
2366 (defun article-hide-pgp ()
2367 "Remove any PGP headers and signatures in the current article."
2371 (let ((inhibit-point-motion-hooks t)
2372 buffer-read-only beg end)
2374 ;; Hide the "header".
2375 (when (re-search-forward "^-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
2376 (gnus-add-wash-type 'pgp)
2377 (delete-region (match-beginning 0) (match-end 0))
2378 ;; Remove armor headers (rfc2440 6.2)
2379 (delete-region (point) (or (re-search-forward "^[ \t]*\n" nil t)
2382 ;; Hide the actual signature.
2383 (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
2384 (setq end (1+ (match-beginning 0)))
2387 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
2389 ;; Perhaps we shouldn't hide to the end of the buffer
2390 ;; if there is no end to the signature?
2392 ;; Hide "- " PGP quotation markers.
2394 (narrow-to-region beg end)
2395 (goto-char (point-min))
2396 (while (re-search-forward "^- " nil t)
2398 (match-beginning 0) (match-end 0)))
2400 (gnus-run-hooks 'gnus-article-hide-pgp-hook))))))
2402 (defun article-hide-pem (&optional arg)
2403 "Toggle hiding of any PEM headers and signatures in the current article.
2404 If given a negative prefix, always show; if given a positive prefix,
2406 (interactive (gnus-article-hidden-arg))
2407 (unless (gnus-article-check-hidden-text 'pem arg)
2409 (let (buffer-read-only end)
2410 (goto-char (point-min))
2411 ;; Hide the horrendously ugly "header".
2412 (when (and (search-forward
2413 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
2415 (setq end (1+ (match-beginning 0))))
2416 (gnus-add-wash-type 'pem)
2417 (gnus-article-hide-text-type
2419 (if (search-forward "\n\n" nil t)
2423 ;; Hide the trailer as well
2424 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
2426 (gnus-article-hide-text-type
2427 (match-beginning 0) (match-end 0) 'pem)))))))
2429 (defun article-strip-banner ()
2430 "Strip the banner specified by the `banner' group parameter."
2434 (let ((inhibit-point-motion-hooks t)
2435 (banner (gnus-parameter-banner gnus-newsgroup-name))
2436 (gnus-signature-limit nil)
2437 buffer-read-only beg end)
2441 ((eq banner 'signature)
2442 (when (gnus-article-narrow-to-signature)
2445 (delete-region (point) (point-max))))
2447 (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
2448 (while (re-search-forward banner nil t)
2449 (delete-region (match-beginning 0) (match-end 0)))))
2451 (while (re-search-forward banner nil t)
2452 (delete-region (match-beginning 0) (match-end 0))))))))))
2454 (defun article-babel ()
2455 "Translate article using an online translation service."
2459 (set-buffer gnus-article-buffer)
2460 (when (article-goto-body)
2461 (let* ((buffer-read-only nil)
2464 (orig (buffer-substring start end))
2465 (trans (babel-as-string orig)))
2467 (narrow-to-region start end)
2468 (delete-region start end)
2471 (defun article-hide-signature (&optional arg)
2472 "Hide the signature in the current article.
2473 If given a negative prefix, always show; if given a positive prefix,
2475 (interactive (gnus-article-hidden-arg))
2481 (article-goto-body))
2482 (goto-char (point-min)))
2483 (unless (gnus-article-check-hidden-text 'signature arg)
2484 (let ((buffer-read-only nil)
2486 (while (setq button (text-property-any button (point-max)
2488 'gnus-signature-toggle))
2489 (setq button (text-property-not-all button (point-max)
2491 'gnus-signature-toggle))
2492 (when (and button (not (eobp)))
2493 (gnus-article-hide-text-type
2495 (next-single-property-change (1+ button) 'mime-view-entity
2498 (gnus-set-mode-line 'article))
2500 (defun article-strip-headers-in-body ()
2501 "Strip offensive headers from bodies."
2505 (let ((case-fold-search t))
2506 (when (looking-at "x-no-archive:")
2507 (gnus-delete-line)))))
2509 (defun article-strip-leading-blank-lines ()
2510 "Remove all blank lines from the beginning of the article."
2513 (let ((inhibit-point-motion-hooks t)
2515 (when (article-goto-body)
2516 (while (and (not (eobp))
2517 (looking-at "[ \t]*$"))
2518 (gnus-delete-line))))))
2520 (defun article-narrow-to-head ()
2521 "Narrow the buffer to the head of the message.
2522 Point is left at the beginning of the narrowed-to region."
2524 (goto-char (point-min))
2525 (if (search-forward "\n\n" nil 1)
2528 (goto-char (point-min)))
2530 (defun article-goto-body ()
2531 "Place point at the start of the body."
2532 (goto-char (point-min))
2534 ;; This variable is only bound when dealing with separate
2536 (article-goto-body-goes-to-point-min-p
2538 ((search-forward "\n\n" nil t)
2541 (goto-char (point-max))
2544 (defun article-strip-multiple-blank-lines ()
2545 "Replace consecutive blank lines with one empty line."
2548 (let ((inhibit-point-motion-hooks t)
2550 ;; First make all blank lines empty.
2552 (while (re-search-forward "^[ \t]+$" nil t)
2553 (unless (gnus-annotation-in-region-p
2554 (match-beginning 0) (match-end 0))
2555 (replace-match "" nil t)))
2556 ;; Then replace multiple empty lines with a single empty line.
2558 (while (re-search-forward "\n\n\\(\n+\\)" nil t)
2559 (unless (gnus-annotation-in-region-p
2560 (match-beginning 0) (match-end 0))
2561 (delete-region (match-beginning 1) (match-end 1)))))))
2563 (defun article-strip-leading-space ()
2564 "Remove all white space from the beginning of the lines in the article."
2567 (let ((inhibit-point-motion-hooks t)
2570 (while (re-search-forward "^[ \t]+" nil t)
2571 (replace-match "" t t)))))
2573 (defun article-strip-trailing-space ()
2574 "Remove all white space from the end of the lines in the article."
2577 (let ((inhibit-point-motion-hooks t)
2580 (while (re-search-forward "[ \t]+$" nil t)
2581 (replace-match "" t t)))))
2583 (defun article-strip-blank-lines ()
2584 "Strip leading, trailing and multiple blank lines."
2586 (article-strip-leading-blank-lines)
2587 (article-remove-trailing-blank-lines)
2588 (article-strip-multiple-blank-lines))
2590 (defun article-strip-all-blank-lines ()
2591 "Strip all blank lines."
2594 (let ((inhibit-point-motion-hooks t)
2597 (while (re-search-forward "^[ \t]*\n" nil t)
2598 (replace-match "" t t)))))
2600 (defun gnus-article-narrow-to-signature ()
2601 "Narrow to the signature; return t if a signature is found, else nil."
2602 (let ((inhibit-point-motion-hooks t))
2603 (when (gnus-article-search-signature)
2605 ;; Check whether we have some limits to what we consider
2606 ;; to be a signature.
2607 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
2608 (list gnus-signature-limit)))
2610 (while (setq limit (pop limits))
2611 (if (or (and (integerp limit)
2612 (< (- (point-max) (point)) limit))
2614 (< (count-lines (point) (point-max)) limit))
2615 (and (gnus-functionp limit)
2617 (and (stringp limit)
2618 (not (re-search-forward limit nil t))))
2619 () ; This limit did not succeed.
2623 (narrow-to-region (point) (point-max))
2626 (defun gnus-article-search-signature ()
2627 "Search the current buffer for the signature separator.
2628 Put point at the beginning of the signature separator."
2629 (let ((cur (point)))
2630 (goto-char (point-max))
2631 (if (if (stringp gnus-signature-separator)
2632 (re-search-backward gnus-signature-separator nil t)
2633 (let ((seps gnus-signature-separator))
2635 (not (re-search-backward (car seps) nil t)))
2642 (defun gnus-article-hidden-arg ()
2643 "Return the current prefix arg as a number, or 0 if no prefix."
2644 (list (if current-prefix-arg
2645 (prefix-numeric-value current-prefix-arg)
2648 (defun gnus-article-check-hidden-text (type arg)
2649 "Return nil if hiding is necessary.
2650 Arg can be nil or a number. nil and positive means hide, negative
2651 means show, 0 means toggle."
2654 (let ((hide (gnus-article-hidden-text-p type)))
2660 (gnus-article-show-hidden-text type)
2663 (if (eq hide 'hidden)
2665 (gnus-article-show-hidden-text type)
2669 (defun gnus-article-hidden-text-p (type)
2670 "Say whether the current buffer contains hidden text of type TYPE."
2671 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
2673 (not (get-text-property pos 'invisible))
2674 (not (get-text-property pos 'dummy-invisible)))
2676 (text-property-any (1+ pos) (point-max) 'article-type type)))
2681 (defun gnus-article-show-hidden-text (type &optional dummy)
2682 "Show all hidden text of type TYPE.
2683 Originally it is hide instead of DUMMY."
2684 (let ((buffer-read-only nil)
2685 (inhibit-point-motion-hooks t))
2686 (gnus-remove-text-properties-when
2688 (point-min) (point-max)
2689 (cons 'article-type (cons type
2690 gnus-hidden-properties)))
2691 (gnus-delete-wash-type type)))
2693 (defconst article-time-units
2694 `((year . ,(* 365.25 24 60 60))
2695 (week . ,(* 7 24 60 60))
2696 (day . ,(* 24 60 60))
2700 "Mapping from time units to seconds.")
2702 (defun article-date-ut (&optional type highlight header)
2703 "Convert DATE date to universal time in the current article.
2704 If TYPE is `local', convert to local time; if it is `lapsed', output
2705 how much time has lapsed since DATE. For `lapsed', the value of
2706 `gnus-article-date-lapsed-new-header' says whether the \"X-Sent:\" header
2707 should replace the \"Date:\" one, or should be added below it."
2708 (interactive (list 'ut t))
2709 (let* ((header (or header
2710 (and (eq 1 (point-min))
2711 (mail-header-date (save-excursion
2712 (set-buffer gnus-summary-buffer)
2713 gnus-current-headers)))
2714 (message-fetch-field "date")
2716 (date (if (vectorp header) (mail-header-date header)
2718 (inhibit-point-motion-hooks t)
2719 bface eface date-pos)
2720 (when (and date (not (string= date "")))
2723 (article-narrow-to-head)
2724 (when (or (and (eq type 'lapsed)
2725 gnus-article-date-lapsed-new-header
2726 ;; Attempt to get the face of X-Sent first.
2727 (re-search-forward "^X-Sent:[ \t]" nil t))
2728 (re-search-forward "^Date:[ \t]" nil t)
2729 ;; If Date is missing, try again for X-Sent.
2730 (re-search-forward "^X-Sent:[ \t]" nil t))
2731 (setq bface (get-text-property (gnus-point-at-bol) 'face)
2732 date (or (get-text-property (gnus-point-at-bol)
2735 eface (get-text-property (1- (gnus-point-at-eol))
2737 (let ((buffer-read-only nil))
2738 ;; Delete any old X-Sent headers.
2739 (when (setq date-pos
2740 (text-property-any (point-min) (point-max)
2741 'article-date-lapsed t))
2742 (goto-char (setq date-pos (set-marker (make-marker) date-pos)))
2743 (delete-region (match-beginning 0)
2744 (progn (forward-line 1) (point))))
2745 (goto-char (point-min))
2746 ;; Delete any old Date headers.
2747 (while (re-search-forward "^Date:[ \t]" nil t)
2749 (setq date-pos (match-beginning 0)))
2750 (unless (and (eq type 'lapsed)
2751 gnus-article-date-lapsed-new-header)
2752 (delete-region (match-beginning 0)
2753 (progn (message-next-header) (point)))))
2756 (goto-char date-pos)
2758 ;; Possibly, Date has been deleted.
2760 (when (and (eq type 'lapsed)
2761 gnus-article-date-lapsed-new-header
2762 (looking-at "Date:"))
2764 (goto-char (point-min)))
2765 (insert (article-make-date-line date type))
2766 (when (eq type 'lapsed)
2767 (put-text-property (gnus-point-at-bol) (point)
2768 'article-date-lapsed t))
2772 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
2773 (put-text-property (match-beginning 1) (1+ (match-end 1))
2774 'original-date date)
2775 (put-text-property (match-beginning 1) (1+ (match-end 1))
2777 (put-text-property (match-beginning 2) (match-end 2)
2780 (defun article-make-date-line (date type)
2781 "Return a DATE line of TYPE."
2782 (unless (memq type '(local ut original user iso8601 lapsed english))
2783 (error "Unknown conversion type: %s" type))
2785 (let ((time (date-to-time date)))
2787 ;; Convert to the local timezone.
2789 (let ((tz (car (current-time-zone time))))
2790 (format "Date: %s %s%02d%02d" (current-time-string time)
2791 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2792 (/ (% (abs tz) 3600) 60))))
2793 ;; Convert to Universal Time.
2796 (current-time-string
2797 (let* ((e (parse-time-string date))
2798 (tm (apply 'encode-time e))
2800 (ls (- (cadr tm) (car (current-time-zone time)))))
2801 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
2802 ((> ls 65535) (list (1+ ms) (- ls 65536)))
2805 ;; Get the original date from the article.
2806 ((eq type 'original)
2807 (concat "Date: " (if (string-match "\n+$" date)
2808 (substring date 0 (match-beginning 0))
2810 ;; Let the user define the format.
2812 (if (gnus-functionp gnus-article-time-format)
2813 (funcall gnus-article-time-format time)
2816 (format-time-string gnus-article-time-format time))))
2819 (let ((tz (car (current-time-zone time))))
2822 (format-time-string "%Y%m%dT%H%M%S" time)
2823 (format "%s%02d%02d"
2824 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2825 (/ (% (abs tz) 3600) 60)))))
2826 ;; Do an X-Sent lapsed format.
2828 ;; If the date is seriously mangled, the timezone functions are
2829 ;; liable to bug out, so we ignore all errors.
2830 (let* ((now (current-time))
2831 (real-time (subtract-time now time))
2832 (real-sec (and real-time
2833 (+ (* (float (car real-time)) 65536)
2835 (sec (and real-time (abs real-sec)))
2845 ;; This is a bit convoluted, but basically we go
2846 ;; through the time units for years, weeks, etc,
2847 ;; and divide things to see whether that results
2848 ;; in positive answers.
2851 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
2852 ;; The (remaining) seconds are too few to
2853 ;; be divided into this time unit.
2855 ;; It's big enough, so we output it.
2856 (setq sec (- sec (* num (cdr unit))))
2858 (concat (if prev ", " "") (int-to-string
2860 " " (symbol-name (car unit))
2861 (if (> num 1) "s" ""))
2863 article-time-units "")
2864 ;; If dates are odd, then it might appear like the
2865 ;; article was sent in the future.
2868 " in the future"))))))
2869 ;; Display the date in proper English
2871 (let ((dtime (decode-time time)))
2874 (number-to-string (nth 3 dtime))
2875 (let ((digit (% (nth 3 dtime) 10)))
2877 ((memq (nth 3 dtime) '(11 12 13)) "th")
2883 (nth (1- (nth 4 dtime)) gnus-english-month-names)
2885 (number-to-string (nth 5 dtime))
2887 (format "%02d" (nth 2 dtime))
2889 (format "%02d" (nth 1 dtime)))))))
2891 (format "Date: %s (from Oort)" date))))
2893 (defun article-date-local (&optional highlight)
2894 "Convert the current article date to the local timezone."
2895 (interactive (list t))
2896 (article-date-ut 'local highlight))
2898 (defun article-date-english (&optional highlight)
2899 "Convert the current article date to something that is proper English."
2900 (interactive (list t))
2901 (article-date-ut 'english highlight))
2903 (defun article-date-original (&optional highlight)
2904 "Convert the current article date to what it was originally.
2905 This is only useful if you have used some other date conversion
2906 function and want to see what the date was before converting."
2907 (interactive (list t))
2908 (article-date-ut 'original highlight))
2910 (defun article-date-lapsed (&optional highlight)
2911 "Convert the current article date to time lapsed since it was sent."
2912 (interactive (list t))
2913 (article-date-ut 'lapsed highlight))
2915 (defun article-update-date-lapsed ()
2916 "Function to be run from a timer to update the lapsed time line."
2917 (let (deactivate-mark)
2922 (set-buffer (window-buffer w))
2923 (when (eq major-mode 'gnus-article-mode)
2924 (goto-char (point-min))
2925 (when (re-search-forward "^X-Sent:" nil t)
2926 (article-date-lapsed t))))
2929 (defun gnus-start-date-timer (&optional n)
2930 "Start a timer to update the X-Sent header in the article buffers.
2931 The numerical prefix says how frequently (in seconds) the function
2936 (gnus-stop-date-timer)
2937 (setq article-lapsed-timer
2938 (nnheader-run-at-time 1 n 'article-update-date-lapsed)))
2940 (defun gnus-stop-date-timer ()
2941 "Stop the X-Sent timer."
2943 (when article-lapsed-timer
2944 (nnheader-cancel-timer article-lapsed-timer)
2945 (setq article-lapsed-timer nil)))
2947 (defun article-date-user (&optional highlight)
2948 "Convert the current article date to the user-defined format.
2949 This format is defined by the `gnus-article-time-format' variable."
2950 (interactive (list t))
2951 (article-date-ut 'user highlight))
2953 (defun article-date-iso8601 (&optional highlight)
2954 "Convert the current article date to ISO8601."
2955 (interactive (list t))
2956 (article-date-ut 'iso8601 highlight))
2958 ;; (defun article-show-all ()
2959 ;; "Show all hidden text in the article buffer."
2963 ;; (let ((buffer-read-only nil))
2964 ;; (gnus-article-unhide-text (point-min) (point-max))
2965 ;; (gnus-remove-text-with-property 'gnus-prev)
2966 ;; (gnus-remove-text-with-property 'gnus-next))))
2968 (defun article-show-all-headers ()
2969 "Show all hidden headers in the article buffer."
2974 (article-narrow-to-head)
2975 (let ((buffer-read-only nil))
2976 (gnus-article-unhide-text (point-min) (point-max))))))
2978 (defun article-remove-leading-whitespace ()
2979 "Remove excessive whitespace from all headers."
2983 (let ((buffer-read-only nil))
2984 (article-narrow-to-head)
2985 (goto-char (point-min))
2986 (while (re-search-forward "^[^ :]+: \\([ \t]+\\)" nil t)
2987 (delete-region (match-beginning 1) (match-end 1)))))))
2989 (defun article-emphasize (&optional arg)
2990 "Emphasize text according to `gnus-emphasis-alist'."
2991 (interactive (gnus-article-hidden-arg))
2992 (unless (gnus-article-check-hidden-text 'emphasis arg)
2996 (with-current-buffer gnus-summary-buffer
2997 gnus-article-emphasis-alist)
2999 gnus-emphasis-alist))
3000 (buffer-read-only nil)
3001 (props (append '(article-type emphasis)
3002 gnus-hidden-properties))
3003 regexp elem beg invisible visible face)
3006 (while (setq elem (pop alist))
3008 (setq regexp (car elem)
3009 invisible (nth 1 elem)
3010 visible (nth 2 elem)
3012 (while (re-search-forward regexp nil t)
3013 (when (and (match-beginning visible) (match-beginning invisible))
3014 (gnus-article-hide-text
3015 (match-beginning invisible) (match-end invisible) props)
3016 (gnus-article-unhide-text-type
3017 (match-beginning visible) (match-end visible) 'emphasis)
3018 (gnus-put-overlay-excluding-newlines
3019 (match-beginning visible) (match-end visible) 'face face)
3020 (gnus-add-wash-type 'emphasis)
3021 (goto-char (match-end invisible)))))))))
3023 (defun gnus-article-setup-highlight-words (&optional highlight-words)
3024 "Setup newsgroup emphasis alist."
3025 (unless gnus-article-emphasis-alist
3026 (let ((name (and gnus-newsgroup-name
3027 (gnus-group-real-name gnus-newsgroup-name))))
3028 (make-local-variable 'gnus-article-emphasis-alist)
3029 (setq gnus-article-emphasis-alist
3031 (let ((alist gnus-group-highlight-words-alist) elem highlight)
3032 (while (setq elem (pop alist))
3033 (when (and name (string-match (car elem) name))
3035 highlight (copy-sequence (cdr elem)))))
3037 (copy-sequence highlight-words)
3038 (if gnus-newsgroup-name
3039 (copy-sequence (gnus-group-find-parameter
3040 gnus-newsgroup-name 'highlight-words t)))
3041 gnus-emphasis-alist)))))
3044 (defvar gnus-summary-article-menu)
3045 (defvar gnus-summary-post-menu))
3047 ;;; Saving functions.
3049 (defun gnus-article-save (save-buffer file &optional num)
3050 "Save the currently selected article."
3051 (unless gnus-save-all-headers
3052 ;; Remove headers according to `gnus-saved-headers'.
3053 (let ((gnus-visible-headers
3054 (or gnus-saved-headers gnus-visible-headers))
3055 (gnus-article-buffer save-buffer))
3057 (set-buffer save-buffer)
3058 (article-hide-headers 1 t))))
3059 (save-window-excursion
3060 (if (not gnus-default-article-saver)
3061 (error "No default saver is defined")
3062 ;; !!! Magic! The saving functions all save
3063 ;; `gnus-save-article-buffer' (or so they think), but we
3064 ;; bind that variable to our save-buffer.
3065 (set-buffer gnus-article-buffer)
3066 (let* ((gnus-save-article-buffer save-buffer)
3069 ((not gnus-prompt-before-saving) 'default)
3070 ((eq gnus-prompt-before-saving 'always) nil)
3072 (gnus-number-of-articles-to-be-saved
3073 (when (eq gnus-prompt-before-saving t)
3075 (set-buffer gnus-article-current-summary)
3076 (funcall gnus-default-article-saver filename)))))
3078 (defun gnus-read-save-file-name (prompt &optional filename
3079 function group headers variable)
3081 (funcall function group headers (symbol-value variable)))
3086 ((eq filename 'default)
3092 (let* ((split-name (gnus-get-split-value gnus-split-methods))
3095 (if (and gnus-number-of-articles-to-be-saved
3096 (> gnus-number-of-articles-to-be-saved 1))
3097 (format "these %d articles"
3098 gnus-number-of-articles-to-be-saved)
3101 ;; Let the split methods have their say.
3103 ;; No split name was found.
3106 (concat prompt " (default "
3107 (file-name-nondirectory default-name) ") ")
3108 (file-name-directory default-name)
3110 ;; A single group name is returned.
3111 ((stringp split-name)
3113 (funcall function split-name headers
3114 (symbol-value variable)))
3116 (concat prompt " (default "
3117 (file-name-nondirectory default-name) ") ")
3118 (file-name-directory default-name)
3120 ;; A single split name was found
3121 ((= 1 (length split-name))
3122 (let* ((name (expand-file-name
3124 gnus-article-save-directory))
3125 (dir (cond ((file-directory-p name)
3126 (file-name-as-directory name))
3127 ((file-exists-p name) name)
3128 (t gnus-article-save-directory))))
3130 (concat prompt " (default " name ") ")
3132 ;; A list of splits was found.
3134 (setq split-name (nreverse split-name))
3136 (let ((file-name-history
3137 (nconc split-name file-name-history)))
3141 (concat prompt " (`M-p' for defaults) ")
3142 gnus-article-save-directory
3144 gnus-article-save-directory)))
3145 (car (push result file-name-history)))))))
3146 ;; Create the directory.
3147 (gnus-make-directory (file-name-directory file))
3148 ;; If we have read a directory, we append the default file name.
3149 (when (file-directory-p file)
3150 (setq file (expand-file-name (file-name-nondirectory
3152 (file-name-as-directory file))))
3153 ;; Possibly translate some characters.
3154 (nnheader-translate-file-chars file))))))
3155 (gnus-make-directory (file-name-directory result))
3156 (set variable result)))
3158 (defun gnus-article-archive-name (group)
3159 "Return the first instance of an \"Archive-name\" in the current buffer."
3160 (let ((case-fold-search t))
3161 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
3162 (nnheader-concat gnus-article-save-directory
3163 (match-string 1)))))
3165 (defun gnus-article-nndoc-name (group)
3166 "If GROUP is an nndoc group, return the name of the parent group."
3167 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
3168 (gnus-group-get-parameter group 'save-article-group)))
3170 (defun gnus-summary-save-in-rmail (&optional filename)
3171 "Append this article to Rmail file.
3172 Optional argument FILENAME specifies file name.
3173 Directory to save to is default to `gnus-article-save-directory'."
3174 (setq filename (gnus-read-save-file-name
3175 "Save %s in rmail file:" filename
3176 gnus-rmail-save-name gnus-newsgroup-name
3177 gnus-current-headers 'gnus-newsgroup-last-rmail))
3178 (gnus-eval-in-buffer-window gnus-save-article-buffer
3182 (gnus-output-to-rmail filename))))
3185 (defun gnus-summary-save-in-mail (&optional filename)
3186 "Append this article to Unix mail file.
3187 Optional argument FILENAME specifies file name.
3188 Directory to save to is default to `gnus-article-save-directory'."
3189 (setq filename (gnus-read-save-file-name
3190 "Save %s in Unix mail file:" filename
3191 gnus-mail-save-name gnus-newsgroup-name
3192 gnus-current-headers 'gnus-newsgroup-last-mail))
3193 (gnus-eval-in-buffer-window gnus-save-article-buffer
3197 (if (and (file-readable-p filename)
3198 (mail-file-babyl-p filename))
3199 (rmail-output-to-rmail-file filename t)
3200 (gnus-output-to-mail filename)))))
3203 (defun gnus-summary-save-in-file (&optional filename overwrite)
3204 "Append this article to file.
3205 Optional argument FILENAME specifies file name.
3206 Directory to save to is default to `gnus-article-save-directory'."
3207 (setq filename (gnus-read-save-file-name
3208 "Save %s in file:" filename
3209 gnus-file-save-name gnus-newsgroup-name
3210 gnus-current-headers 'gnus-newsgroup-last-file))
3211 (gnus-eval-in-buffer-window gnus-save-article-buffer
3215 (when (and overwrite
3216 (file-exists-p filename))
3217 (delete-file filename))
3218 (gnus-output-to-file filename))))
3221 (defun gnus-summary-write-to-file (&optional filename)
3222 "Write this article to a file, overwriting it if the file exists.
3223 Optional argument FILENAME specifies file name.
3224 The directory to save in defaults to `gnus-article-save-directory'."
3225 (gnus-summary-save-in-file nil t))
3227 (defun gnus-summary-save-body-in-file (&optional filename)
3228 "Append this article body to a file.
3229 Optional argument FILENAME specifies file name.
3230 The directory to save in defaults to `gnus-article-save-directory'."
3231 (setq filename (gnus-read-save-file-name
3232 "Save %s body in file:" filename
3233 gnus-file-save-name gnus-newsgroup-name
3234 gnus-current-headers 'gnus-newsgroup-last-file))
3235 (gnus-eval-in-buffer-window gnus-save-article-buffer
3239 (when (article-goto-body)
3240 (narrow-to-region (point) (point-max)))
3241 (gnus-output-to-file filename))))
3244 (defun gnus-summary-save-in-pipe (&optional command)
3245 "Pipe this article to subprocess."
3247 (cond ((and (eq command 'default)
3248 gnus-last-shell-command)
3249 gnus-last-shell-command)
3254 "Shell command on %s: "
3255 (if (and gnus-number-of-articles-to-be-saved
3256 (> gnus-number-of-articles-to-be-saved 1))
3257 (format "these %d articles"
3258 gnus-number-of-articles-to-be-saved)
3260 gnus-last-shell-command))))
3261 (when (string-equal command "")
3262 (if gnus-last-shell-command
3263 (setq command gnus-last-shell-command)
3264 (error "A command is required")))
3265 (gnus-eval-in-buffer-window gnus-article-buffer
3268 (shell-command-on-region (point-min) (point-max) command nil)))
3269 (setq gnus-last-shell-command command))
3271 (defun gnus-summary-pipe-to-muttprint (&optional command)
3272 "Pipe this article to muttprint."
3273 (setq command (read-string
3274 "Print using command: " gnus-summary-muttprint-program
3275 nil gnus-summary-muttprint-program))
3276 (gnus-summary-save-in-pipe command))
3278 ;;; Article file names when saving.
3280 (defun gnus-capitalize-newsgroup (newsgroup)
3281 "Capitalize NEWSGROUP name."
3282 (when (not (zerop (length newsgroup)))
3283 (concat (char-to-string (upcase (aref newsgroup 0)))
3284 (substring newsgroup 1))))
3286 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
3287 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
3288 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
3289 Otherwise, it is like ~/News/news/group/num."
3292 (concat (if (gnus-use-long-file-name 'not-save)
3293 (gnus-capitalize-newsgroup newsgroup)
3294 (gnus-newsgroup-directory-form newsgroup))
3295 "/" (int-to-string (mail-header-number headers)))
3296 gnus-article-save-directory)))
3298 (string-equal (file-name-directory default)
3299 (file-name-directory last-file))
3300 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
3302 (or last-file default))))
3304 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
3305 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
3306 If variable `gnus-use-long-file-name' is non-nil, it is
3307 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
3310 (concat (if (gnus-use-long-file-name 'not-save)
3312 (gnus-newsgroup-directory-form newsgroup))
3313 "/" (int-to-string (mail-header-number headers)))
3314 gnus-article-save-directory)))
3316 (string-equal (file-name-directory default)
3317 (file-name-directory last-file))
3318 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
3320 (or last-file default))))
3322 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
3323 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
3324 If variable `gnus-use-long-file-name' is non-nil, it is
3325 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
3328 (if (gnus-use-long-file-name 'not-save)
3331 (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup))
3333 gnus-article-save-directory)))
3335 (defun gnus-sender-save-name (newsgroup headers &optional last-file)
3336 "Generate file name from sender."
3337 (let ((from (mail-header-from headers)))
3339 (if (and from (string-match "\\([^ <]+\\)@" from))
3340 (match-string 1 from)
3342 gnus-article-save-directory)))
3344 (defun article-verify-x-pgp-sig ()
3347 (if (gnus-buffer-live-p gnus-original-article-buffer)
3348 (let ((sig (with-current-buffer gnus-original-article-buffer
3349 (gnus-fetch-field "X-PGP-Sig")))
3353 (mml2015-clear-verify-function))
3355 (insert-buffer gnus-original-article-buffer)
3356 (setq items (split-string sig))
3357 (message-narrow-to-head)
3358 (let ((inhibit-point-motion-hooks t)
3359 (case-fold-search t))
3360 ;; Don't verify multiple headers.
3361 (setq headers (mapconcat (lambda (header)
3363 (mail-fetch-field header) "\n"))
3364 (split-string (nth 1 items) ",") "")))
3365 (delete-region (point-min) (point-max))
3366 (insert "-----BEGIN PGP SIGNED MESSAGE-----\n\n")
3367 (insert "X-Signed-Headers: " (nth 1 items) "\n")
3372 (if (looking-at "^-")
3375 (insert "\n-----BEGIN PGP SIGNATURE-----\n")
3376 (insert "Version: " (car items) "\n\n")
3377 (insert (mapconcat 'identity (cddr items) "\n"))
3378 (insert "\n-----END PGP SIGNATURE-----\n")
3379 (let ((mm-security-handle (list (format "multipart/signed"))))
3380 (mml2015-clean-buffer)
3381 (let ((coding-system-for-write (or gnus-newsgroup-charset
3383 (funcall (mml2015-clear-verify-function)))
3385 (or (mm-handle-multipart-ctl-parameter
3386 mm-security-handle 'gnus-details)
3387 (mm-handle-multipart-ctl-parameter
3388 mm-security-handle 'gnus-info)))))
3390 (let (buffer-read-only bface eface)
3392 (message-narrow-to-head)
3393 (goto-char (point-max))
3395 (setq bface (get-text-property (gnus-point-at-bol) 'face)
3396 eface (get-text-property (1- (gnus-point-at-eol)) 'face))
3397 (message-remove-header "X-Gnus-PGP-Verify")
3398 (if (re-search-forward "^X-PGP-Sig:" nil t)
3400 (goto-char (point-max)))
3401 (narrow-to-region (point) (point))
3402 (insert "X-Gnus-PGP-Verify: " info "\n")
3403 (goto-char (point-min))
3406 (if (not (looking-at "^[ \t]"))
3410 (goto-char (point-min))
3411 (when (looking-at "\\([^:]+\\): *")
3412 (put-text-property (match-beginning 1) (1+ (match-end 1))
3414 (put-text-property (match-end 0) (point-max)
3415 'face eface)))))))))
3417 (defun article-verify-cancel-lock ()
3418 "Verify Cancel-Lock header."
3420 (if (gnus-buffer-live-p gnus-original-article-buffer)
3421 (canlock-verify gnus-original-article-buffer)))
3428 (setq afunc (car func)
3431 gfunc (intern (format "gnus-%s" func))))
3433 (when (fboundp afunc)
3434 `(lambda (&optional interactive &rest args)
3435 ,(documentation afunc t)
3436 (interactive (list t))
3438 (set-buffer gnus-article-buffer)
3440 (call-interactively ',afunc)
3441 (apply ',afunc args))))))))
3442 '(article-hide-headers
3443 article-verify-x-pgp-sig
3444 article-verify-cancel-lock
3445 article-hide-boring-headers
3446 article-toggle-headers
3447 article-treat-overstrike
3448 article-fill-long-lines
3449 article-capitalize-sentences
3451 article-remove-leading-whitespace
3452 article-display-x-face
3453 article-de-quoted-unreadable
3454 article-de-base64-unreadable
3457 article-unsplit-urls
3458 article-hide-list-identifiers
3460 article-strip-banner
3463 article-hide-signature
3464 article-strip-headers-in-body
3465 article-remove-trailing-blank-lines
3466 article-strip-leading-blank-lines
3467 article-strip-multiple-blank-lines
3468 article-strip-leading-space
3469 article-strip-trailing-space
3470 article-strip-blank-lines
3471 article-strip-all-blank-lines
3473 article-date-english
3474 article-date-iso8601
3475 article-date-original
3477 article-decode-mime-words
3478 article-decode-charset
3479 article-decode-encoded-words
3483 article-treat-dumbquotes
3484 article-normalize-headers
3485 (article-show-all-headers . gnus-article-show-all-headers)
3486 ;; (article-show-all . gnus-article-show-all)
3490 ;;; Gnus article mode
3493 (put 'gnus-article-mode 'mode-class 'special)
3495 (gnus-define-keys gnus-article-mode-map
3496 " " gnus-article-goto-next-page
3497 "\177" gnus-article-goto-prev-page
3498 [delete] gnus-article-goto-prev-page
3499 [backspace] gnus-article-goto-prev-page
3500 "\C-c^" gnus-article-refer-article
3501 "h" gnus-article-show-summary
3502 "s" gnus-article-show-summary
3503 "\C-c\C-m" gnus-article-mail
3504 "?" gnus-article-describe-briefly
3505 "e" gnus-summary-edit-article
3506 "<" beginning-of-buffer
3508 "\C-c\C-i" gnus-info-find-node
3510 "R" gnus-article-reply-with-original
3511 "F" gnus-article-followup-with-original
3512 "\C-hk" gnus-article-describe-key
3513 "\C-hc" gnus-article-describe-key-briefly
3515 "\C-d" gnus-article-read-summary-keys
3516 "\M-*" gnus-article-read-summary-keys
3517 "\M-#" gnus-article-read-summary-keys
3518 "\M-^" gnus-article-read-summary-keys
3519 "\M-g" gnus-article-read-summary-keys)
3521 ;; Define almost undefined keys to `gnus-article-read-summary-keys'.
3525 (push (char-to-string key) keys)
3527 (dolist (elem (accessible-keymaps gnus-summary-mode-map))
3528 (setq key (car elem))
3529 (when (and (> (length key) 0)
3530 (not (eq 'menu-bar (aref key 0)))
3531 (symbolp (lookup-key gnus-summary-mode-map key)))
3534 (unless (lookup-key gnus-article-mode-map key)
3535 (define-key gnus-article-mode-map key 'gnus-article-read-summary-keys))))
3537 (defun gnus-article-make-menu-bar ()
3538 (unless (boundp 'gnus-article-commands-menu)
3539 (gnus-summary-make-menu-bar))
3540 (gnus-turn-off-edit-menu 'article)
3541 (unless (boundp 'gnus-article-article-menu)
3543 gnus-article-article-menu gnus-article-mode-map ""
3545 ["Scroll forwards" gnus-article-goto-next-page t]
3546 ["Scroll backwards" gnus-article-goto-prev-page t]
3547 ["Show summary" gnus-article-show-summary t]
3548 ["Fetch Message-ID at point" gnus-article-refer-article t]
3549 ["Mail to address at point" gnus-article-mail t]
3550 ["Send a bug report" gnus-bug t]))
3553 gnus-article-treatment-menu gnus-article-mode-map ""
3554 ;; Fixme: this should use :active (and maybe :visible).
3556 ["Hide headers" gnus-article-toggle-headers t]
3557 ["Hide signature" gnus-article-hide-signature t]
3558 ["Hide citation" gnus-article-hide-citation t]
3559 ["Treat overstrike" gnus-article-treat-overstrike t]
3560 ["Remove carriage return" gnus-article-remove-cr t]
3561 ["Remove leading whitespace" gnus-article-remove-leading-whitespace t]
3562 ["Treat html" gnus-article-wash-html t]
3563 ["Remove newlines from within URLs" gnus-article-unsplit-urls t]
3564 ["Decode HZ" gnus-article-decode-HZ t]))
3566 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
3568 ;; Note "Post" menu is defined in gnus-sum.el for consistency
3570 (gnus-run-hooks 'gnus-article-menu-hook)))
3572 ;; Fixme: do something for the Emacs tool bar in Article mode a la
3575 (defun gnus-article-mode ()
3576 "Major mode for displaying an article.
3578 All normal editing commands are switched off.
3580 The following commands are available in addition to all summary mode
3582 \\<gnus-article-mode-map>
3583 \\[gnus-article-next-page]\t Scroll the article one page forwards
3584 \\[gnus-article-prev-page]\t Scroll the article one page backwards
3585 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
3586 \\[gnus-article-show-summary]\t Display the summary buffer
3587 \\[gnus-article-mail]\t Send a reply to the address near point
3588 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
3589 \\[gnus-info-find-node]\t Go to the Gnus info node"
3591 (gnus-simplify-mode-line)
3592 (setq mode-name "Article")
3593 (setq major-mode 'gnus-article-mode)
3594 (make-local-variable 'minor-mode-alist)
3595 (unless (assq 'gnus-show-mime minor-mode-alist)
3596 (push (list 'gnus-show-mime " MIME") minor-mode-alist))
3597 (use-local-map gnus-article-mode-map)
3598 (when (gnus-visual-p 'article-menu 'menu)
3599 (gnus-article-make-menu-bar))
3600 (gnus-update-format-specifications nil 'article-mode)
3601 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
3602 (make-local-variable 'gnus-page-broken)
3603 (make-local-variable 'gnus-button-marker-list)
3604 (make-local-variable 'gnus-article-current-summary)
3605 (make-local-variable 'gnus-article-mime-handles)
3606 (make-local-variable 'gnus-article-decoded-p)
3607 (make-local-variable 'gnus-article-mime-handle-alist)
3608 (make-local-variable 'gnus-article-wash-types)
3609 (make-local-variable 'gnus-article-image-alist)
3610 (make-local-variable 'gnus-article-charset)
3611 (make-local-variable 'gnus-article-ignored-charsets)
3612 (gnus-set-default-directory)
3613 (buffer-disable-undo)
3614 (setq buffer-read-only t)
3615 (set-syntax-table gnus-article-mode-syntax-table)
3616 (gnus-run-hooks 'gnus-article-mode-hook))
3618 (defun gnus-article-setup-buffer ()
3619 "Initialize the article buffer."
3620 (let* ((name (if gnus-single-article-buffer "*Article*"
3621 (concat "*Article " gnus-newsgroup-name "*")))
3623 (progn (string-match "\\*Article" name)
3624 (concat " *Original Article"
3625 (substring name (match-end 0))))))
3626 (setq gnus-article-buffer name)
3627 (setq gnus-original-article-buffer original)
3628 (setq gnus-article-mime-handle-alist nil)
3629 ;; This might be a variable local to the summary buffer.
3630 (unless gnus-single-article-buffer
3632 (set-buffer gnus-summary-buffer)
3633 (setq gnus-article-buffer name)
3634 (setq gnus-original-article-buffer original)
3635 (gnus-set-global-variables)))
3636 (gnus-article-setup-highlight-words)
3637 ;; Init original article buffer.
3639 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
3640 (set-buffer-multibyte t)
3641 (setq major-mode 'gnus-original-article-mode)
3642 (make-local-variable 'gnus-original-article))
3643 (if (get-buffer name)
3646 (buffer-disable-undo)
3647 (setq buffer-read-only t)
3648 (unless (eq major-mode 'gnus-article-mode)
3649 (gnus-article-mode))
3652 (set-buffer (gnus-get-buffer-create name))
3654 (make-local-variable 'gnus-summary-buffer)
3655 (gnus-summary-set-local-parameters gnus-newsgroup-name)
3656 (current-buffer)))))
3658 ;; Set article window start at LINE, where LINE is the number of lines
3659 ;; from the head of the article.
3660 (defun gnus-article-set-window-start (&optional line)
3662 (gnus-get-buffer-window gnus-article-buffer t)
3664 (set-buffer gnus-article-buffer)
3665 (goto-char (point-min))
3668 (gnus-message 6 "Moved to bookmark")
3669 (search-forward "\n\n" nil t)
3673 ;;; @@ article filters
3676 (defun gnus-article-display-mime-message ()
3677 "Article display method for MIME message."
3678 ;; called from `gnus-original-article-buffer'.
3679 (let (charset all-headers)
3680 (with-current-buffer gnus-summary-buffer
3681 (setq charset default-mime-charset
3682 all-headers gnus-have-all-headers))
3683 (make-local-variable 'default-mime-charset)
3684 (setq default-mime-charset charset)
3685 (with-current-buffer (get-buffer-create gnus-article-buffer)
3686 (make-local-variable 'default-mime-charset)
3687 (setq default-mime-charset charset))
3688 (mime-display-message mime-message-structure
3689 gnus-article-buffer nil gnus-article-mode-map)
3691 (gnus-article-hide-headers nil -1)))
3692 (run-hooks 'gnus-mime-article-prepare-hook))
3694 (defun gnus-article-display-traditional-message ()
3695 "Article display method for traditional message."
3696 (set-buffer gnus-article-buffer)
3697 (let (buffer-read-only)
3699 (insert-buffer-substring gnus-original-article-buffer)))
3701 (defun gnus-article-make-full-mail-header (&optional number charset)
3702 "Create a new mail header structure in a raw article buffer."
3703 (unless (and number charset)
3704 (save-current-buffer
3705 (set-buffer gnus-summary-buffer)
3707 (setq number (or (cdr gnus-article-current) 0)))
3709 (setq charset (or default-mime-charset 'x-ctext)))))
3710 (goto-char (point-min))
3711 (let ((header-end (if (search-forward "\n\n" nil t)
3713 (goto-char (point-max))))
3714 (chars (- (point-max) (point)))
3715 (lines (count-lines (point) (point-max)))
3716 (default-mime-charset charset)
3718 (narrow-to-region (point-min) header-end)
3719 (setq xref (std11-fetch-field "xref"))
3721 (make-full-mail-header
3723 (std11-fetch-field "subject")
3724 (std11-fetch-field "from")
3725 (std11-fetch-field "date")
3726 (std11-fetch-field "message-id")
3727 (std11-fetch-field "references")
3730 (when xref (concat "Xref: " xref)))
3733 (defun gnus-article-prepare (article &optional all-headers header)
3734 "Prepare ARTICLE in article mode buffer.
3735 ARTICLE should either be an article number or a Message-ID.
3736 If ARTICLE is an id, HEADER should be the article headers.
3737 If ALL-HEADERS is non-nil, no headers are hidden."
3739 ;; Make sure we start in a summary buffer.
3740 (unless (eq major-mode 'gnus-summary-mode)
3741 (set-buffer gnus-summary-buffer))
3742 (setq gnus-summary-buffer (current-buffer))
3743 (let* ((gnus-article (if header (mail-header-number header) article))
3744 (summary-buffer (current-buffer))
3745 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
3746 (group gnus-newsgroup-name)
3749 (gnus-article-setup-buffer)
3750 (set-buffer gnus-article-buffer)
3751 ;; Deactivate active regions.
3752 (when (and (boundp 'transient-mark-mode)
3753 transient-mark-mode)
3754 (setq mark-active nil))
3755 (if (not (setq result (let ((buffer-read-only nil))
3756 (gnus-request-article-this-buffer
3758 ;; There is no such article.
3760 (when (and (numberp article)
3761 (not (memq article gnus-newsgroup-sparse)))
3762 (setq gnus-article-current
3763 (cons gnus-newsgroup-name article))
3764 (set-buffer gnus-summary-buffer)
3765 (setq gnus-current-article article)
3766 (if (eq (gnus-article-mark article) gnus-undownloaded-mark)
3768 (gnus-summary-set-agent-mark article)
3769 (message "Message marked for downloading"))
3770 (gnus-summary-mark-article article gnus-canceled-mark)
3771 (unless (memq article gnus-newsgroup-sparse)
3772 (gnus-error 1 "No such article (may have expired or been canceled)")))))
3773 (if (or (eq result 'pseudo)
3774 (eq result 'nneething))
3777 (set-buffer summary-buffer)
3778 (push article gnus-newsgroup-history)
3779 (setq gnus-last-article gnus-current-article
3780 gnus-current-article 0
3781 gnus-current-headers nil
3782 gnus-article-current nil)
3783 (if (eq result 'nneething)
3784 (gnus-configure-windows 'summary)
3785 (gnus-configure-windows 'article))
3786 (gnus-set-global-variables))
3787 (let ((gnus-article-mime-handle-alist-1
3788 gnus-article-mime-handle-alist))
3789 (gnus-set-mode-line 'article)))
3790 ;; The result from the `request' was an actual article -
3791 ;; or at least some text that is now displayed in the
3793 (when (and (numberp article)
3794 (not (eq article gnus-current-article)))
3795 ;; Seems like a new article has been selected.
3796 ;; `gnus-current-article' must be an article number.
3798 (set-buffer summary-buffer)
3799 (push article gnus-newsgroup-history)
3800 (setq gnus-last-article gnus-current-article
3801 gnus-current-article article
3802 gnus-current-headers
3803 (gnus-summary-article-header gnus-current-article)
3804 gnus-article-current
3805 (cons gnus-newsgroup-name gnus-current-article))
3806 (unless (vectorp gnus-current-headers)
3807 (setq gnus-current-headers nil))
3808 (gnus-summary-goto-subject gnus-current-article)
3809 (when (gnus-summary-show-thread)
3810 ;; If the summary buffer really was folded, the
3811 ;; previous goto may not actually have gone to
3812 ;; the right article, but the thread root instead.
3814 (gnus-summary-goto-subject gnus-current-article))
3815 (gnus-run-hooks 'gnus-mark-article-hook)
3816 (gnus-set-mode-line 'summary)
3817 (when (gnus-visual-p 'article-highlight 'highlight)
3818 (gnus-run-hooks 'gnus-visual-mark-article-hook))
3819 ;; Set the global newsgroup variables here.
3820 (gnus-set-global-variables)
3821 (setq gnus-have-all-headers
3822 (or all-headers gnus-show-all-headers))))
3824 (gnus-configure-windows 'article))
3825 (when (or (numberp article)
3827 (gnus-article-prepare-display)
3829 (goto-char (point-min))
3830 (setq gnus-page-broken
3831 (when gnus-break-pages
3832 (gnus-narrow-to-page)
3834 (let ((gnus-article-mime-handle-alist-1
3835 gnus-article-mime-handle-alist))
3836 (gnus-set-mode-line 'article))
3838 (set-window-point (get-buffer-window (current-buffer)) (point))
3839 (gnus-configure-windows 'article)
3842 (defun gnus-article-prepare-mime-display (&optional number)
3843 (goto-char (point-min))
3844 (when (re-search-forward "^[^\t ]+:" nil t)
3845 (goto-char (match-beginning 0)))
3846 (let ((entity (if (eq 1 (point-min))
3847 (get-text-property 1 'mime-view-entity)
3848 (get-text-property (point) 'mime-view-entity)))
3849 last-entity child-entity next type)
3850 (setq child-entity (mime-entity-children entity))
3852 (setq last-entity (nth (1- (length child-entity))
3854 (setq last-entity entity))
3856 (narrow-to-region (point)
3857 (if (search-forward "\n\n" nil t)
3860 (gnus-treat-article 'head)
3861 (put-text-property (point-min) (point-max) 'article-treated-header t)
3862 (goto-char (point-max)))
3863 (while (and (not (eobp)) entity)
3864 (setq next (set-marker
3866 (next-single-property-change (point) 'mime-view-entity
3868 (let ((types (mime-entity-content-type entity)))
3869 (while (eq 'multipart (mime-content-type-primary-type types))
3870 (setq entity (car (mime-entity-children entity))
3871 types (mime-entity-content-type entity)))
3873 (setq type (format "%s/%s"
3874 (mime-content-type-primary-type types)
3875 (mime-content-type-subtype types)))))
3876 (if (string-equal type "message/rfc822")
3879 (let ((children (mime-entity-children entity))
3882 (setq last-children (nth (1- (length children)) children))
3885 (not (eq last-children
3886 (get-text-property next 'mime-view-entity)))
3888 (next-single-property-change next
3890 nil (point-max)))))))
3891 (setq next (next-single-property-change next 'mime-view-entity
3894 (narrow-to-region (point) next)
3895 (gnus-article-prepare-mime-display)
3896 (goto-char (point-max)))
3897 (setq entity (get-text-property (point) 'mime-view-entity)))
3899 (narrow-to-region (point) next)
3900 ;; Kludge. We have to count true number, but for now,
3901 ;; part number is here only to achieve `last'.
3902 (gnus-treat-article nil 1
3903 (if (eq entity last-entity)
3906 (goto-char (point-max)))
3907 (setq entity (get-text-property next 'mime-view-entity))))))
3910 (defun gnus-article-prepare-display ()
3911 "Make the current buffer look like a nice article."
3912 (let ((gnus-article-buffer (current-buffer))
3914 (unless (eq major-mode 'gnus-article-mode)
3915 (gnus-article-mode))
3916 (setq buffer-read-only nil
3917 gnus-button-marker-list nil
3918 gnus-article-wash-types nil
3919 gnus-article-image-alist nil)
3922 (static-if (featurep 'xemacs)
3923 (map-extents (lambda (extent maparg) (delete-extent extent)))
3924 (let ((lists (overlay-lists)))
3925 (dolist (overlay (nconc (car lists) (cdr lists)))
3926 (delete-overlay overlay)))))
3927 (gnus-run-hooks 'gnus-tmp-internal-hook))
3928 (set-buffer gnus-original-article-buffer)
3930 (setq mime-message-structure gnus-current-headers)
3931 (mime-buffer-entity-set-buffer-internal mime-message-structure
3932 gnus-original-article-buffer)
3933 (mime-entity-set-representation-type-internal mime-message-structure
3934 'mime-buffer-entity)
3935 (luna-send mime-message-structure 'initialize-instance
3936 mime-message-structure)
3938 (let (mime-display-header-hook mime-display-text/plain-hook)
3939 (funcall gnus-article-display-method-for-mime))
3940 (funcall gnus-article-display-method-for-traditional))
3941 ;; Call the treatment functions.
3942 (let ((inhibit-read-only t))
3946 (gnus-article-prepare-mime-display)
3947 (narrow-to-region (goto-char (point-min))
3948 (if (search-forward "\n\n" nil t)
3951 (gnus-treat-article 'head)
3952 (put-text-property (point-min) (point-max) 'article-treated-header t)
3953 (goto-char (point-max))
3955 (narrow-to-region (point) (point-max))
3956 (gnus-treat-article nil))
3957 (put-text-property (point-min) (point-max) 'read-only nil)))
3958 (gnus-run-hooks 'gnus-article-prepare-hook))
3960 (defun gnus-article-decode-article-as-default-mime-charset ()
3961 "Decode an article as `default-mime-charset'. It won't work if the
3962 value of the variable `gnus-show-mime' is non-nil."
3963 (unless gnus-show-mime
3964 (set (make-local-variable 'default-mime-charset)
3965 (with-current-buffer gnus-summary-buffer
3966 default-mime-charset))
3967 (decode-mime-charset-region (point-min) (point-max)
3968 default-mime-charset)))
3971 ;;; Gnus MIME viewing functions
3974 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
3975 "Format of the MIME buttons.
3977 Valid specifiers include:
3979 %T MIME type, along with additional info
3980 %n The `name' parameter
3981 %d The description, if any
3982 %l The length of the encoded part
3983 %p The part identifier number
3984 %e Dots if the part isn't displayed
3986 General format specifiers can also be used. See
3987 (gnus)Formatting Variables.")
3989 (defvar gnus-mime-button-line-format-alist
3990 '((?t gnus-tmp-type ?s)
3991 (?T gnus-tmp-type-long ?s)
3992 (?n gnus-tmp-name ?s)
3993 (?d gnus-tmp-description ?s)
3995 (?l gnus-tmp-length ?d)
3996 (?e gnus-tmp-dots ?s)))
3998 (defvar gnus-mime-button-commands
3999 '((gnus-article-press-button "\r" "Toggle Display")
4000 (gnus-mime-view-part "v" "View Interactively...")
4001 (gnus-mime-view-part-as-type "t" "View As Type...")
4002 (gnus-mime-view-part-as-charset "C" "View As charset...")
4003 (gnus-mime-save-part "o" "Save...")
4004 (gnus-mime-save-part-and-strip "\C-o" "Save and Strip")
4005 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
4006 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
4007 (gnus-mime-internalize-part "E" "View Internally")
4008 (gnus-mime-externalize-part "e" "View Externally")
4009 (gnus-mime-print-part "p" "Print")
4010 (gnus-mime-pipe-part "|" "Pipe To Command...")
4011 (gnus-mime-action-on-part "." "Take action on the part")))
4013 (defun gnus-article-mime-part-status ()
4014 (with-current-buffer gnus-article-buffer
4015 (let ((entity (get-text-property (point-min) 'mime-view-entity))
4018 (setq children (mime-entity-children entity))
4019 (setq children (length children)))
4022 (format " (%d parts)" children))
4025 (defvar gnus-mime-button-map
4026 (let ((map (make-sparse-keymap)))
4027 (unless (>= (string-to-number emacs-version) 21)
4028 ;; XEmacs doesn't care.
4029 (set-keymap-parent map gnus-article-mode-map))
4030 (define-key map gnus-mouse-2 'gnus-article-push-button)
4031 (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
4032 (dolist (c gnus-mime-button-commands)
4033 (define-key map (cadr c) (car c)))
4036 (defun gnus-mime-button-menu (event)
4037 "Construct a context-sensitive menu of MIME commands."
4039 (save-window-excursion
4040 (let ((pos (event-start event)))
4041 (select-window (posn-window pos))
4042 (goto-char (posn-point pos))
4043 (gnus-article-check-buffer)
4044 (let ((response (x-popup-menu
4046 ("" ,@(mapcar (lambda (c)
4047 (cons (caddr c) (car c)))
4048 gnus-mime-button-commands))))))
4050 (call-interactively response))))))
4052 (defun gnus-mime-view-all-parts (&optional handles)
4053 "View all the MIME parts."
4055 (save-current-buffer
4056 (set-buffer gnus-article-buffer)
4057 (let ((handles (or handles gnus-article-mime-handles))
4058 (mail-parse-charset gnus-newsgroup-charset)
4059 (mail-parse-ignored-charsets
4060 (with-current-buffer gnus-summary-buffer
4061 gnus-newsgroup-ignored-charsets)))
4063 (mm-remove-parts handles)
4064 (goto-char (point-min))
4065 (or (search-forward "\n\n") (goto-char (point-max)))
4066 (let (buffer-read-only)
4067 (delete-region (point) (point-max))
4068 (mm-display-parts handles))))))
4070 (defun gnus-mime-save-part-and-strip ()
4071 "Save the MIME part under point then replace it with an external body."
4073 (gnus-article-check-buffer)
4074 (let* ((data (get-text-property (point) 'gnus-data))
4076 (handles gnus-article-mime-handles))
4077 (if (mm-multiple-handles gnus-article-mime-handles)
4078 (error "This function is not implemented"))
4079 (setq file (and data (mm-save-part data)))
4081 (with-current-buffer (mm-handle-buffer data)
4083 (insert "Content-Type: " (mm-handle-media-type data))
4084 (mml-insert-parameter-string (cdr (mm-handle-type data))
4087 (insert "Content-ID: " (message-make-message-id) "\n")
4088 (insert "Content-Transfer-Encoding: binary\n")
4091 (cdr (mm-make-handle nil
4092 `("message/external-body"
4093 (access-type . "LOCAL-FILE")
4095 (set-buffer gnus-summary-buffer)
4096 (gnus-article-edit-article
4099 (let ((mail-parse-charset (or gnus-article-charset
4100 ',gnus-newsgroup-charset))
4101 (mail-parse-ignored-charsets
4102 (or gnus-article-ignored-charsets
4103 ',gnus-newsgroup-ignored-charsets))
4104 (mbl mml-buffer-list))
4105 (setq mml-buffer-list nil)
4106 (insert-buffer gnus-original-article-buffer)
4107 (mime-to-mml ',handles)
4108 (setq gnus-article-mime-handles nil)
4109 (let ((mbl1 mml-buffer-list))
4110 (setq mml-buffer-list mbl)
4111 (set (make-local-variable 'mml-buffer-list) mbl1))
4112 ;; LOCAL argument of add-hook differs between GNU Emacs
4113 ;; and XEmacs. make-local-hook makes sure they are local.
4114 (make-local-hook 'kill-buffer-hook)
4115 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
4116 `(lambda (no-highlight)
4117 (let ((mail-parse-charset (or gnus-article-charset
4118 ',gnus-newsgroup-charset))
4119 (message-options message-options)
4120 (message-options-set-recipient)
4121 (mail-parse-ignored-charsets
4122 (or gnus-article-ignored-charsets
4123 ',gnus-newsgroup-ignored-charsets)))
4125 (mml-destroy-buffers)
4126 (remove-hook 'kill-buffer-hook
4127 'mml-destroy-buffers t)
4128 (kill-local-variable 'mml-buffer-list))
4129 (gnus-summary-edit-article-done
4130 ,(or (mail-header-references gnus-current-headers) "")
4131 ,(gnus-group-read-only-p)
4132 ,gnus-summary-buffer no-highlight))))))
4134 (defun gnus-mime-save-part ()
4135 "Save the MIME part under point."
4137 (gnus-article-check-buffer)
4138 (let ((data (get-text-property (point) 'gnus-data)))
4140 (mm-save-part data))))
4142 (defun gnus-mime-pipe-part ()
4143 "Pipe the MIME part under point to a process."
4145 (gnus-article-check-buffer)
4146 (let ((data (get-text-property (point) 'gnus-data)))
4148 (mm-pipe-part data))))
4150 (defun gnus-mime-view-part ()
4151 "Interactively choose a viewing method for the MIME part under point."
4153 (gnus-article-check-buffer)
4154 (let ((data (get-text-property (point) 'gnus-data)))
4156 (setq gnus-article-mime-handles
4158 gnus-article-mime-handles (setq data (copy-sequence data))))
4159 (mm-interactively-view-part data))))
4161 (defun gnus-mime-view-part-as-type-internal ()
4162 (gnus-article-check-buffer)
4163 (let* ((name (mail-content-type-get
4164 (mm-handle-type (get-text-property (point) 'gnus-data))
4166 (def-type (and name (mm-default-file-encoding name))))
4167 (and def-type (cons def-type 0))))
4169 (defun gnus-mime-view-part-as-type (&optional mime-type)
4170 "Choose a MIME media type, and view the part as such."
4173 (setq mime-type (completing-read
4174 "View as MIME type: "
4175 (mapcar #'list (mailcap-mime-types))
4177 (gnus-mime-view-part-as-type-internal))))
4178 (gnus-article-check-buffer)
4179 (let ((handle (get-text-property (point) 'gnus-data)))
4182 (mm-make-handle (mm-handle-buffer handle)
4183 (cons mime-type (cdr (mm-handle-type handle)))
4184 (mm-handle-encoding handle)
4185 (mm-handle-undisplayer handle)
4186 (mm-handle-disposition handle)
4187 (mm-handle-description handle)
4189 (mm-handle-id handle)))
4190 (setq gnus-article-mime-handles
4191 (mm-merge-handles gnus-article-mime-handles handle))
4192 (gnus-mm-display-part handle))))
4194 (defun gnus-mime-copy-part (&optional handle)
4195 "Put the MIME part under point into a new buffer."
4197 (gnus-article-check-buffer)
4198 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4199 (contents (and handle (mm-get-part handle)))
4201 (file-name-nondirectory
4203 (mail-content-type-get (mm-handle-type handle) 'name)
4204 (mail-content-type-get (mm-handle-type handle)
4207 (buffer (and base (generate-new-buffer base))))
4209 (switch-to-buffer buffer)
4211 ;; We do it this way to make `normal-mode' set the appropriate mode.
4214 (setq buffer-file-name (expand-file-name base))
4216 (setq buffer-file-name nil))
4217 (goto-char (point-min)))))
4219 (defun gnus-mime-print-part (&optional handle filename)
4220 "Print the MIME part under point."
4221 (interactive (list nil (ps-print-preprint current-prefix-arg)))
4222 (gnus-article-check-buffer)
4223 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4224 (contents (and handle (mm-get-part handle)))
4225 (file (make-temp-name (expand-file-name "mm." mm-tmp-directory)))
4226 (printer (mailcap-mime-info (mm-handle-type handle) "print")))
4231 (with-temp-file file
4233 (call-process shell-file-name nil
4234 (generate-new-buffer " *mm*")
4236 shell-command-switch
4238 printer file (mm-handle-type handle))))
4242 (gnus-print-buffer))
4243 (ps-despool filename)))))
4245 (defun gnus-mime-inline-part (&optional handle arg)
4246 "Insert the MIME part under point into the current buffer."
4247 (interactive (list nil current-prefix-arg))
4248 (gnus-article-check-buffer)
4249 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4254 (if (and (not arg) (mm-handle-undisplayer handle))
4255 (mm-remove-part handle)
4256 (setq contents (mm-get-part handle))
4259 (setq charset (or (mail-content-type-get
4260 (mm-handle-type handle) 'charset)
4261 gnus-newsgroup-charset)))
4263 (if (mm-handle-undisplayer handle)
4264 (mm-remove-part handle))
4267 gnus-summary-show-article-charset-alist))
4268 (mm-read-coding-system "Charset: ")))))
4270 (mm-insert-inline handle
4272 (setq charset (mm-charset-to-coding-system
4274 (not (eq charset 'ascii)))
4275 (mm-decode-coding-string contents charset)
4279 (defun gnus-mime-view-part-as-charset (&optional handle arg)
4280 "Insert the MIME part under point into the current buffer using the
4282 (interactive (list nil current-prefix-arg))
4283 (gnus-article-check-buffer)
4284 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4289 (if (mm-handle-undisplayer handle)
4290 (mm-remove-part handle))
4291 (let ((gnus-newsgroup-charset
4293 gnus-summary-show-article-charset-alist))
4294 (mm-read-coding-system "Charset: ")))
4295 (gnus-newsgroup-ignored-charsets 'gnus-all))
4296 (gnus-article-press-button)))))
4298 (defun gnus-mime-externalize-part (&optional handle)
4299 "View the MIME part under point with an external viewer."
4301 (gnus-article-check-buffer)
4302 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4303 (mm-user-display-methods nil)
4304 (mm-inlined-types nil)
4305 (mail-parse-charset gnus-newsgroup-charset)
4306 (mail-parse-ignored-charsets
4307 (save-excursion (set-buffer gnus-summary-buffer)
4308 gnus-newsgroup-ignored-charsets)))
4310 (if (mm-handle-undisplayer handle)
4311 (mm-remove-part handle)
4312 (mm-display-part handle)))))
4314 (defun gnus-mime-internalize-part (&optional handle)
4315 "View the MIME part under point with an internal viewer.
4316 If no internal viewer is available, use an external viewer."
4318 (gnus-article-check-buffer)
4319 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4320 (mm-inlined-types '(".*"))
4321 (mm-inline-large-images t)
4322 (mail-parse-charset gnus-newsgroup-charset)
4323 (mail-parse-ignored-charsets
4324 (save-excursion (set-buffer gnus-summary-buffer)
4325 gnus-newsgroup-ignored-charsets)))
4327 (if (mm-handle-undisplayer handle)
4328 (mm-remove-part handle)
4329 (mm-display-part handle)))))
4331 (defun gnus-mime-action-on-part (&optional action)
4332 "Do something with the MIME attachment at \(point\)."
4334 (list (completing-read "Action: " gnus-mime-action-alist)))
4335 (gnus-article-check-buffer)
4336 (let ((action-pair (assoc action gnus-mime-action-alist)))
4338 (funcall (cdr action-pair)))))
4340 (defun gnus-article-part-wrapper (n function)
4341 (save-current-buffer
4342 (set-buffer gnus-article-buffer)
4343 (when (> n (length gnus-article-mime-handle-alist))
4344 (error "No such part"))
4345 (gnus-article-goto-part n)
4346 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
4347 (funcall function handle))))
4349 (defun gnus-article-pipe-part (n)
4350 "Pipe MIME part N, which is the numerical prefix."
4352 (gnus-article-part-wrapper n 'mm-pipe-part))
4354 (defun gnus-article-save-part (n)
4355 "Save MIME part N, which is the numerical prefix."
4357 (gnus-article-part-wrapper n 'mm-save-part))
4359 (defun gnus-article-interactively-view-part (n)
4360 "View MIME part N interactively, which is the numerical prefix."
4362 (gnus-article-part-wrapper n 'mm-interactively-view-part))
4364 (defun gnus-article-copy-part (n)
4365 "Copy MIME part N, which is the numerical prefix."
4367 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
4369 (defun gnus-article-view-part-as-charset (n)
4370 "Copy MIME part N, which is the numerical prefix."
4372 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-charset))
4374 (defun gnus-article-externalize-part (n)
4375 "View MIME part N externally, which is the numerical prefix."
4377 (gnus-article-part-wrapper n 'gnus-mime-externalize-part))
4379 (defun gnus-article-inline-part (n)
4380 "Inline MIME part N, which is the numerical prefix."
4382 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
4384 (defun gnus-article-mime-match-handle-first (condition)
4386 (let ((alist gnus-article-mime-handle-alist) ihandle n)
4387 (while (setq ihandle (pop alist))
4389 ((functionp condition)
4390 (funcall condition (cdr ihandle)))
4391 ((eq condition 'undisplayed)
4392 (not (or (mm-handle-undisplayer (cdr ihandle))
4393 (equal (mm-handle-media-type (cdr ihandle))
4394 "multipart/alternative"))))
4395 ((eq condition 'undisplayed-alternative)
4396 (not (mm-handle-undisplayer (cdr ihandle))))
4398 (gnus-article-goto-part (car ihandle))
4399 (or (not n) (< (car ihandle) n)))
4400 (setq n (car ihandle))))
4404 (defun gnus-article-view-part (&optional n)
4405 "View MIME part N, which is the numerical prefix."
4407 (save-current-buffer
4408 (set-buffer gnus-article-buffer)
4409 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
4410 gnus-article-mime-match-handle-function)))
4411 (when (> n (length gnus-article-mime-handle-alist))
4412 (error "No such part"))
4413 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
4414 (when (gnus-article-goto-part n)
4415 (if (equal (car handle) "multipart/alternative")
4416 (gnus-article-press-button)
4417 (when (eq (gnus-mm-display-part handle) 'internal)
4418 (gnus-set-window-start)))))))
4420 (defsubst gnus-article-mime-total-parts ()
4421 (if (bufferp (car gnus-article-mime-handles))
4423 (1- (length gnus-article-mime-handles))))
4425 (defun gnus-mm-display-part (handle)
4426 "Display HANDLE and fix MIME button."
4427 (let ((id (get-text-property (point) 'gnus-part))
4432 (let ((window (selected-window))
4433 (mail-parse-charset gnus-newsgroup-charset)
4434 (mail-parse-ignored-charsets
4435 (if (gnus-buffer-live-p gnus-summary-buffer)
4437 (set-buffer gnus-summary-buffer)
4438 gnus-newsgroup-ignored-charsets)
4442 (let ((win (gnus-get-buffer-window (current-buffer) t))
4445 (select-window win))
4448 (if (mm-handle-displayed-p handle)
4449 ;; This will remove the part.
4450 (mm-display-part handle)
4452 (narrow-to-region (point)
4453 (if (eobp) (point) (1+ (point))))
4454 (mm-display-part handle)
4455 ;; We narrow to the part itself and
4456 ;; then call the treatment functions.
4457 (goto-char (point-min))
4459 (narrow-to-region (point) (point-max))
4462 (gnus-article-mime-total-parts)
4463 (mm-handle-media-type handle)))))
4464 (if (window-live-p window)
4465 (select-window window)))))
4467 (delete-region (gnus-point-at-bol) (progn (forward-line 1) (point)))
4468 (gnus-insert-mime-button
4469 handle id (list (mm-handle-displayed-p handle)))
4470 (goto-char point))))
4472 (defun gnus-article-goto-part (n)
4473 "Go to MIME part N."
4474 (let ((point (text-property-any (point-min) (point-max) 'gnus-part n)))
4476 (goto-char point))))
4478 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
4479 (let ((gnus-tmp-name
4480 (or (mail-content-type-get (mm-handle-type handle) 'name)
4481 (mail-content-type-get (mm-handle-disposition handle) 'filename)
4482 (mail-content-type-get (mm-handle-type handle) 'url)
4484 (gnus-tmp-type (mm-handle-media-type handle))
4485 (gnus-tmp-description
4486 (mail-decode-encoded-word-string (or (mm-handle-description handle)
4489 (if (if displayed (car displayed)
4490 (mm-handle-displayed-p handle))
4492 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
4494 gnus-tmp-type-long b e)
4495 (when (string-match ".*/" gnus-tmp-name)
4496 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
4497 (setq gnus-tmp-type-long (concat gnus-tmp-type
4498 (and (not (equal gnus-tmp-name ""))
4499 (concat "; " gnus-tmp-name))))
4500 (unless (equal gnus-tmp-description "")
4501 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
4506 gnus-mime-button-line-format gnus-mime-button-line-format-alist
4507 `(,@(gnus-local-map-property gnus-mime-button-map)
4508 gnus-callback gnus-mm-display-part
4509 gnus-part ,gnus-tmp-id
4510 article-type annotation
4513 (widget-convert-button
4516 :action 'gnus-widget-press-button
4517 :button-keymap gnus-mime-button-map
4519 (lambda (widget/window &optional overlay pos)
4520 ;; Needed to properly clear the message due to a bug in
4521 ;; wid-edit (XEmacs only).
4522 (if (boundp 'help-echo-owns-message)
4523 (setq help-echo-owns-message t))
4525 "%S: %s the MIME part; %S: more options"
4526 (aref gnus-mouse-2 0)
4527 ;; XEmacs will get a single widget arg; Emacs 21 will get
4528 ;; window, overlay, position.
4529 (if (mm-handle-displayed-p
4531 (with-current-buffer (gnus-overlay-buffer overlay)
4532 (widget-get (widget-at (gnus-overlay-start overlay))
4534 (widget-get widget/window :mime-handle)))
4536 (aref gnus-down-mouse-3 0))))))
4538 (defun gnus-widget-press-button (elems el)
4539 (goto-char (widget-get elems :from))
4540 (gnus-article-press-button))
4542 (defvar gnus-displaying-mime nil)
4544 (defun gnus-display-mime (&optional ihandles)
4545 "Display the MIME parts."
4547 (save-selected-window
4548 (let ((window (get-buffer-window gnus-article-buffer))
4551 (select-window window)
4552 ;; We have to do this since selecting the window
4553 ;; may change the point. So we set the window point.
4554 (set-window-point window point)))
4555 (let* ((handles (or ihandles (mm-dissect-buffer
4556 gnus-article-no-strict-mime)
4558 buffer-read-only handle name type b e display)
4559 (when (and (not ihandles)
4560 (not gnus-displaying-mime))
4561 ;; Top-level call; we clean up.
4562 (when gnus-article-mime-handles
4563 (mm-destroy-parts gnus-article-mime-handles)
4564 (setq gnus-article-mime-handle-alist nil));; A trick.
4565 (setq gnus-article-mime-handles handles)
4566 ;; We allow users to glean info from the handles.
4567 (when gnus-article-mime-part-function
4568 (gnus-mime-part-function handles)))
4570 (or (not (stringp (car handles)))
4573 (when (and (not ihandles)
4574 (not gnus-displaying-mime))
4575 ;; Clean up for mime parts.
4577 (delete-region (point) (point-max)))
4578 (let ((gnus-displaying-mime t))
4579 (gnus-mime-display-part handles)))
4582 (narrow-to-region (point) (point-max))
4583 (gnus-treat-article nil 1 1)
4586 ;; Highlight the headers.
4590 (narrow-to-region (point-min) (point))
4591 (gnus-treat-article 'head))))))))
4593 (defvar gnus-mime-display-multipart-as-mixed nil)
4594 (defvar gnus-mime-display-multipart-alternative-as-mixed nil)
4595 (defvar gnus-mime-display-multipart-related-as-mixed nil)
4597 (defun gnus-mime-display-part (handle)
4600 ((not (stringp (car handle)))
4601 (gnus-mime-display-single handle))
4602 ;; User-defined multipart
4603 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
4604 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
4606 ;; multipart/alternative
4607 ((and (equal (car handle) "multipart/alternative")
4608 (not (or gnus-mime-display-multipart-as-mixed
4609 gnus-mime-display-multipart-alternative-as-mixed)))
4610 (let ((id (1+ (length gnus-article-mime-handle-alist))))
4611 (push (cons id handle) gnus-article-mime-handle-alist)
4612 (gnus-mime-display-alternative (cdr handle) nil nil id)))
4613 ;; multipart/related
4614 ((and (equal (car handle) "multipart/related")
4615 (not (or gnus-mime-display-multipart-as-mixed
4616 gnus-mime-display-multipart-related-as-mixed)))
4617 ;;;!!!We should find the start part, but we just default
4618 ;;;!!!to the first part.
4619 ;;(gnus-mime-display-part (cadr handle))
4620 ;;;!!! Most multipart/related is an HTML message plus images.
4621 ;;;!!! Unfortunately we are unable to let W3 display those
4622 ;;;!!! included images, so we just display it as a mixed multipart.
4623 ;;(gnus-mime-display-mixed (cdr handle))
4624 ;;;!!! No, w3 can display everything just fine.
4625 (gnus-mime-display-part (cadr handle)))
4626 ((equal (car handle) "multipart/signed")
4627 (gnus-add-wash-type 'signed)
4628 (gnus-mime-display-security handle))
4629 ((equal (car handle) "multipart/encrypted")
4630 (gnus-add-wash-type 'encrypted)
4631 (gnus-mime-display-security handle))
4632 ;; Other multiparts are handled like multipart/mixed.
4634 (gnus-mime-display-mixed (cdr handle)))))
4636 (defun gnus-mime-part-function (handles)
4637 (if (stringp (car handles))
4638 (mapcar 'gnus-mime-part-function (cdr handles))
4639 (funcall gnus-article-mime-part-function handles)))
4641 (defun gnus-mime-display-mixed (handles)
4642 (mapcar 'gnus-mime-display-part handles))
4644 (defun gnus-mime-display-single (handle)
4645 (let ((type (mm-handle-media-type handle))
4646 (ignored gnus-ignored-mime-types)
4653 (when (string-match (pop ignored) type)
4654 (throw 'ignored nil)))
4655 (if (and (setq not-attachment
4656 (and (not (mm-inline-override-p handle))
4657 (or (not (mm-handle-disposition handle))
4658 (equal (car (mm-handle-disposition handle))
4660 (mm-attachment-override-p handle))))
4661 (mm-automatic-display-p handle)
4663 (mm-inlinable-p handle)
4664 (mm-inlined-p handle))
4665 (mm-automatic-external-display-p type)))
4667 (when (equal (mm-handle-media-supertype handle) "text")
4669 (let ((id (1+ (length gnus-article-mime-handle-alist)))
4671 (push (cons id handle) gnus-article-mime-handle-alist)
4672 (when (or (not display)
4673 (not (gnus-unbuttonized-mime-type-p type)))
4674 ;(gnus-article-insert-newline)
4675 (gnus-insert-mime-button
4676 handle id (list (or display (and not-attachment text))))
4677 (gnus-article-insert-newline)
4678 ;(gnus-article-insert-newline)
4679 ;; Remember modify the number of forward lines.
4687 (let ((mail-parse-charset gnus-newsgroup-charset)
4688 (mail-parse-ignored-charsets
4689 (save-excursion (condition-case ()
4690 (set-buffer gnus-summary-buffer)
4692 gnus-newsgroup-ignored-charsets)))
4693 (mm-display-part handle t))
4694 (goto-char (point-max)))
4695 ((and text not-attachment)
4699 (gnus-article-insert-newline)
4700 (mm-insert-inline handle (mm-get-part handle))
4701 (goto-char (point-max))))
4705 (narrow-to-region beg (point))
4708 (gnus-article-mime-total-parts)
4709 (mm-handle-media-type handle)))))))))
4711 (defun gnus-unbuttonized-mime-type-p (type)
4712 "Say whether TYPE is to be unbuttonized."
4713 (unless gnus-inhibit-mime-unbuttonizing
4715 (let ((types gnus-unbuttonized-mime-types))
4717 (when (string-match (pop types) type)
4718 (throw 'found t)))))
4720 (let ((types gnus-buttonized-mime-types))
4722 (when (string-match (pop types) type)
4723 (throw 'found t)))))))))
4725 (defun gnus-article-insert-newline ()
4726 "Insert a newline, but mark it as undeletable."
4727 (gnus-put-text-property
4728 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
4730 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
4731 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
4734 handle buffer-read-only from props begend not-pref)
4735 (save-window-excursion
4738 (narrow-to-region (car ibegend)
4741 (goto-char (car ibegend))
4744 (delete-region (point-min) (point-max))
4745 (mm-remove-parts handles))
4746 (setq begend (list (point-marker)))
4748 (unless (setq not-pref (cadr (member preferred ihandles)))
4749 (setq not-pref (car ihandles)))
4752 (not (gnus-unbuttonized-mime-type-p
4753 "multipart/alternative")))
4754 (gnus-add-text-properties
4757 (insert (format "%d. " id))
4761 (unless ,(not ibegend)
4762 (setq gnus-article-mime-handle-alist
4763 ',gnus-article-mime-handle-alist))
4764 (gnus-mime-display-alternative
4765 ',ihandles ',not-pref ',begend ,id))
4766 ,@(gnus-local-map-property gnus-mime-button-map)
4767 ,gnus-mouse-face-prop ,gnus-article-mouse-face
4768 face ,gnus-article-button-face
4771 (widget-convert-button 'link from (point)
4772 :action 'gnus-widget-press-button
4773 :button-keymap gnus-widget-button-keymap)
4775 (while (setq handle (pop handles))
4776 (gnus-add-text-properties
4779 (insert (format "(%c) %-18s"
4780 (if (equal handle preferred) ?* ? )
4781 (mm-handle-media-type handle)))
4785 (unless ,(not ibegend)
4786 (setq gnus-article-mime-handle-alist
4787 ',gnus-article-mime-handle-alist))
4788 (gnus-mime-display-alternative
4789 ',ihandles ',handle ',begend ,id))
4790 ,@(gnus-local-map-property gnus-mime-button-map)
4791 ,gnus-mouse-face-prop ,gnus-article-mouse-face
4792 face ,gnus-article-button-face
4795 (widget-convert-button 'link from (point)
4796 :action 'gnus-widget-press-button
4797 :button-keymap gnus-widget-button-keymap)
4801 (if (stringp (car preferred))
4802 (gnus-display-mime preferred)
4803 (let ((mail-parse-charset gnus-newsgroup-charset)
4804 (mail-parse-ignored-charsets
4805 (save-excursion (set-buffer gnus-summary-buffer)
4806 gnus-newsgroup-ignored-charsets)))
4807 (mm-display-part preferred)
4811 (narrow-to-region (car begend) (point-max))
4813 nil (length gnus-article-mime-handle-alist)
4814 (gnus-article-mime-total-parts)
4815 (mm-handle-media-type handle))))))
4816 (goto-char (point-max))
4817 (setcdr begend (point-marker)))))
4819 (goto-char point))))
4821 (defconst gnus-article-wash-status-strings
4822 (let ((alist '((cite "c" "Possible hidden citation text"
4823 " " "All citation text visible")
4824 (headers "h" "Hidden headers"
4825 " " "All headers visible.")
4826 (pgp "p" "Encrypted or signed message status hidden"
4827 " " "No hidden encryption nor digital signature status")
4828 (signature "s" "Signature has been hidden"
4829 " " "Signature is visible")
4830 (overstrike "o" "Overstrike (^H) characters applied"
4831 " " "No overstrike characters applied")
4832 (gnus-show-mime "m" "Mime processing is activated"
4833 " " "Mime processing is not activated")
4834 (emphasis "e" "/*_Emphasis_*/ characters applied"
4835 " " "No /*_emphasis_*/ characters applied")))
4837 (dolist (entry alist result)
4838 (let ((key (nth 0 entry))
4839 (on (copy-sequence (nth 1 entry)))
4840 (on-help (nth 2 entry))
4841 (off (copy-sequence (nth 3 entry)))
4842 (off-help (nth 4 entry)))
4843 (put-text-property 0 1 'help-echo on-help on)
4844 (put-text-property 0 1 'help-echo off-help off)
4845 (push (list key on off) result))))
4846 "Alist of strings describing wash status in the mode line.
4847 Each entry has the form (KEY ON OF), where the KEY is a symbol
4848 representing the particular washing function, ON is the string to use
4849 in the article mode line when the washing function is active, and OFF
4850 is the string to use when it is inactive.")
4852 (defun gnus-article-wash-status-entry (key value)
4853 (let ((entry (assoc key gnus-article-wash-status-strings)))
4854 (if value (nth 1 entry) (nth 2 entry))))
4856 (defun gnus-article-wash-status ()
4857 "Return a string which display status of article washing."
4859 (set-buffer gnus-article-buffer)
4860 (let ((cite (memq 'cite gnus-article-wash-types))
4861 (headers (memq 'headers gnus-article-wash-types))
4862 (boring (memq 'boring-headers gnus-article-wash-types))
4863 (pgp (memq 'pgp gnus-article-wash-types))
4864 (pem (memq 'pem gnus-article-wash-types))
4865 (signed (memq 'signed gnus-article-wash-types))
4866 (encrypted (memq 'encrypted gnus-article-wash-types))
4867 (signature (memq 'signature gnus-article-wash-types))
4868 (overstrike (memq 'overstrike gnus-article-wash-types))
4869 (emphasis (memq 'emphasis gnus-article-wash-types)))
4871 (gnus-article-wash-status-entry 'cite cite)
4872 (gnus-article-wash-status-entry 'headers (or headers boring))
4873 (gnus-article-wash-status-entry 'pgp (or pgp pem signed encrypted))
4874 (gnus-article-wash-status-entry 'signature signature)
4875 (gnus-article-wash-status-entry 'overstrike overstrike)
4876 (gnus-article-wash-status-entry 'gnus-show-mime gnus-show-mime)
4877 (gnus-article-wash-status-entry 'emphasis emphasis)))))
4879 (defun gnus-add-wash-type (type)
4880 "Add a washing of TYPE to the current status."
4881 (add-to-list 'gnus-article-wash-types type))
4883 (defun gnus-delete-wash-type (type)
4884 "Add a washing of TYPE to the current status."
4885 (setq gnus-article-wash-types (delq type gnus-article-wash-types)))
4887 (defun gnus-add-image (category image)
4888 "Add IMAGE of CATEGORY to the list of displayed images."
4889 (let ((entry (assq category gnus-article-image-alist)))
4891 (setq entry (list category))
4892 (push entry gnus-article-image-alist))
4893 (nconc entry (list image))))
4895 (defun gnus-delete-images (category)
4896 "Delete all images in CATEGORY."
4897 (let ((entry (assq category gnus-article-image-alist)))
4898 (dolist (image (cdr entry))
4899 (gnus-remove-image image))
4900 (setq gnus-article-image-alist (delq entry gnus-article-image-alist))
4901 (gnus-delete-wash-type category)))
4903 (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
4905 (defun gnus-article-maybe-hide-headers ()
4906 "Hide unwanted headers if `gnus-have-all-headers' is nil.
4907 Provided for backwards compatibility."
4908 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
4909 (not (save-excursion (set-buffer gnus-summary-buffer)
4910 gnus-have-all-headers)))
4911 (not gnus-inhibit-hiding))
4912 (gnus-article-hide-headers)))
4916 (defun gnus-output-to-file (file-name)
4917 "Append the current article to a file named FILE-NAME."
4918 (let ((artbuf (current-buffer)))
4920 (insert-buffer-substring artbuf)
4921 ;; Append newline at end of the buffer as separator, and then
4923 (goto-char (point-max))
4925 (let ((file-name-coding-system nnmail-pathname-coding-system)
4926 (pathname-coding-system nnmail-pathname-coding-system))
4927 (write-region-as-binary (point-min) (point-max) file-name 'append))
4930 (defun gnus-narrow-to-page (&optional arg)
4931 "Narrow the article buffer to a page.
4932 If given a numerical ARG, move forward ARG pages."
4934 (setq arg (if arg (prefix-numeric-value arg) 0))
4936 (set-buffer gnus-article-buffer)
4937 (goto-char (point-min))
4939 ;; Remove any old next/prev buttons.
4940 (when (gnus-visual-p 'page-marker)
4941 (let ((buffer-read-only nil))
4942 (gnus-remove-text-with-property 'gnus-prev)
4943 (gnus-remove-text-with-property 'gnus-next)))
4946 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
4948 (re-search-forward page-delimiter nil 'move arg)))
4949 (goto-char (match-end 0)))
4952 (if (re-search-forward page-delimiter nil 'move)
4955 (when (and (gnus-visual-p 'page-marker)
4956 (not (= (point-min) 1)))
4958 (goto-char (point-min))
4959 (gnus-insert-prev-page-button)))
4960 (when (and (gnus-visual-p 'page-marker)
4961 (< (+ (point-max) 2) (buffer-size)))
4963 (goto-char (point-max))
4964 (gnus-insert-next-page-button)))))
4966 ;; Article mode commands
4968 (defun gnus-article-goto-next-page ()
4969 "Show the next page of the article."
4971 (when (gnus-article-next-page)
4972 (goto-char (point-min))
4973 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
4975 (defun gnus-article-goto-prev-page ()
4976 "Show the next page of the article."
4978 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
4979 (gnus-article-prev-page nil)))
4981 (defun gnus-article-next-page (&optional lines)
4982 "Show the next page of the current article.
4983 If end of article, return non-nil. Otherwise return nil.
4984 Argument LINES specifies lines to be scrolled up."
4986 (let ((start (window-start))
4987 end-of-buffer end-of-page)
4989 (move-to-window-line -1)
4990 (if (<= (point) start)
4993 (setq start (point)))
4996 (unless (or (cond ((eq (1+ (buffer-size)) (point))
4997 (and (pos-visible-in-window-p)
4998 (setq end-of-buffer t)))
5000 (setq end-of-page t)))
5002 (move-to-window-line lines)
5003 (unless (search-backward "\n\n" nil t)
5004 (setq start (point)))))
5005 (cond (end-of-buffer t)
5007 (gnus-narrow-to-page 1)
5011 (set-window-start (selected-window) start)
5012 (let (window-pixel-scroll-increment)
5016 (defun gnus-article-prev-page (&optional lines)
5017 "Show previous page of current article.
5018 Argument LINES specifies lines to be scrolled down."
5020 (let (beginning-of-buffer beginning-of-page)
5022 (move-to-window-line 0)
5023 (cond ((eq 1 (point))
5024 (setq beginning-of-buffer t))
5026 (setq beginning-of-page t))))
5027 (cond (beginning-of-buffer)
5029 (gnus-narrow-to-page -1))
5032 (let (window-pixel-scroll-increment)
5033 (scroll-down lines))
5034 (beginning-of-buffer
5035 (goto-char (point-min))))))))
5037 (defun gnus-article-refer-article ()
5038 "Read article specified by message-id around point."
5040 (let ((point (point)))
5041 (search-forward ">" nil t) ;Move point to end of "<....>".
5042 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
5043 (let ((message-id (match-string 1)))
5045 (set-buffer gnus-summary-buffer)
5046 (gnus-summary-refer-article message-id))
5048 (error "No references around point"))))
5050 (defun gnus-article-show-summary ()
5051 "Reconfigure windows to show summary buffer."
5053 (if (not (gnus-buffer-live-p gnus-summary-buffer))
5054 (error "There is no summary buffer for this article buffer")
5055 (gnus-article-set-globals)
5056 (gnus-configure-windows 'article)
5057 (gnus-summary-goto-subject gnus-current-article)
5058 (gnus-summary-position-point)))
5060 (defun gnus-article-describe-briefly ()
5061 "Describe article mode commands briefly."
5063 (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")))
5065 (defun gnus-article-summary-command ()
5066 "Execute the last keystroke in the summary buffer."
5068 (let ((obuf (current-buffer))
5069 (owin (current-window-configuration))
5071 (switch-to-buffer gnus-article-current-summary 'norecord)
5072 (setq func (lookup-key (current-local-map) (this-command-keys)))
5073 (call-interactively func)
5075 (set-window-configuration owin)
5076 (set-window-point (get-buffer-window (current-buffer)) (point))))
5078 (defun gnus-article-summary-command-nosave ()
5079 "Execute the last keystroke in the summary buffer."
5082 (pop-to-buffer gnus-article-current-summary 'norecord)
5083 (setq func (lookup-key (current-local-map) (this-command-keys)))
5084 (call-interactively func)))
5086 (defun gnus-article-check-buffer ()
5087 "Beep if not in an article buffer."
5088 (unless (eq (get-buffer gnus-article-buffer) (current-buffer))
5089 (error "Command invoked outside of a Gnus article buffer")))
5091 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
5092 "Read a summary buffer key sequence and execute it from the article buffer."
5094 (gnus-article-check-buffer)
5096 '("q" "Q" "c" "r" "\C-c\C-f" "m" "a" "f"
5097 "Zc" "ZC" "ZE" "ZJ" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
5098 "=" "^" "\M-^" "|"))
5104 '("n" "Gn" "p" "Gp"))
5107 (set-buffer gnus-article-current-summary)
5108 (let (gnus-pick-mode)
5109 (push (or key last-command-event) unread-command-events)
5110 (setq keys (static-if (featurep 'xemacs)
5111 (events-to-keys (read-key-sequence nil))
5112 (read-key-sequence nil)))))
5115 (if (or (member keys nosaves)
5116 (member keys nosave-but-article)
5117 (member keys nosave-in-article))
5119 (save-window-excursion
5120 (pop-to-buffer gnus-article-current-summary 'norecord)
5121 ;; We disable the pick minor mode commands.
5122 (let (gnus-pick-mode)
5123 (setq func (lookup-key (current-local-map) keys))))
5127 (unless (member keys nosave-in-article)
5128 (set-buffer gnus-article-current-summary))
5129 (call-interactively func)
5130 (setq new-sum-point (point)))
5131 (when (member keys nosave-but-article)
5132 (pop-to-buffer gnus-article-buffer 'norecord)))
5133 ;; These commands should restore window configuration.
5134 (let ((obuf (current-buffer))
5135 (owin (current-window-configuration))
5137 (summary gnus-article-current-summary)
5138 func in-buffer selected)
5139 (if not-restore-window
5140 (pop-to-buffer summary 'norecord)
5141 (switch-to-buffer summary 'norecord))
5142 (setq in-buffer (current-buffer))
5143 ;; We disable the pick minor mode commands.
5144 (if (and (setq func (let (gnus-pick-mode)
5145 (lookup-key (current-local-map) keys)))
5148 (call-interactively func)
5149 (setq new-sum-point (point))
5150 (when (eq in-buffer (current-buffer))
5151 (setq selected (gnus-summary-select-article))
5153 (unless not-restore-window
5154 (set-window-configuration owin))
5155 (when (eq selected 'old)
5157 (set-window-start (get-buffer-window (current-buffer))
5159 (set-window-point (get-buffer-window (current-buffer))
5161 (let ((win (get-buffer-window gnus-article-current-summary)))
5163 (set-window-point win new-sum-point)))) )
5164 (switch-to-buffer gnus-article-buffer)
5167 (defun gnus-article-describe-key (key)
5168 "Display documentation of the function invoked by KEY. KEY is a string."
5169 (interactive "kDescribe key: ")
5170 (gnus-article-check-buffer)
5171 (if (eq (key-binding key) 'gnus-article-read-summary-keys)
5173 (set-buffer gnus-article-current-summary)
5174 (let (gnus-pick-mode)
5175 (if (featurep 'xemacs)
5177 (push (elt key 0) unread-command-events)
5178 (setq key (events-to-keys
5179 (read-key-sequence "Describe key: "))))
5180 (setq unread-command-events
5182 (lambda (x) (if (>= x 128) (list 'meta (- x 128)) x))
5184 (setq key (read-key-sequence "Describe key: "))))
5186 (describe-key key)))
5188 (defun gnus-article-describe-key-briefly (key &optional insert)
5189 "Display documentation of the function invoked by KEY. KEY is a string."
5190 (interactive "kDescribe key: \nP")
5191 (gnus-article-check-buffer)
5192 (if (eq (key-binding key) 'gnus-article-read-summary-keys)
5194 (set-buffer gnus-article-current-summary)
5195 (let (gnus-pick-mode)
5196 (if (featurep 'xemacs)
5198 (push (elt key 0) unread-command-events)
5199 (setq key (events-to-keys
5200 (read-key-sequence "Describe key: "))))
5201 (setq unread-command-events
5203 (lambda (x) (if (>= x 128) (list 'meta (- x 128)) x))
5205 (setq key (read-key-sequence "Describe key: "))))
5206 (describe-key-briefly key insert))
5207 (describe-key-briefly key insert)))
5209 (defun gnus-article-reply-with-original (&optional wide)
5210 "Start composing a reply mail to the current message.
5211 The text in the region will be yanked. If the region isn't active,
5212 the entire article will be yanked."
5214 (let ((article (cdr gnus-article-current)) cont)
5216 (gnus-summary-reply (list (list article)) wide)
5217 (setq cont (buffer-substring (point) (mark t)))
5218 ;; Deactivate active regions.
5219 (when (and (boundp 'transient-mark-mode)
5220 transient-mark-mode)
5221 (setq mark-active nil))
5223 (list (list article cont)) wide))))
5225 (defun gnus-article-followup-with-original ()
5226 "Compose a followup to the current article.
5227 The text in the region will be yanked. If the region isn't active,
5228 the entire article will be yanked."
5230 (let ((article (cdr gnus-article-current))
5233 (gnus-summary-followup (list (list article)))
5234 (setq cont (buffer-substring (point) (mark t)))
5235 ;; Deactivate active regions.
5236 (when (and (boundp 'transient-mark-mode)
5237 transient-mark-mode)
5238 (setq mark-active nil))
5239 (gnus-summary-followup
5240 (list (list article cont))))))
5242 (defun gnus-article-hide (&optional arg force)
5243 "Hide all the gruft in the current article.
5244 This means that PGP stuff, signatures, cited text and (some)
5245 headers will be hidden.
5246 If given a prefix, show the hidden text instead."
5247 (interactive (append (gnus-article-hidden-arg) (list 'force)))
5248 (gnus-article-hide-headers arg)
5249 (gnus-article-hide-list-identifiers arg)
5250 (gnus-article-hide-pgp arg)
5251 (gnus-article-hide-citation-maybe arg force)
5252 (gnus-article-hide-signature arg))
5254 (defun gnus-article-maybe-highlight ()
5255 "Do some article highlighting if article highlighting is requested."
5256 (when (gnus-visual-p 'article-highlight 'highlight)
5257 (gnus-article-highlight-some)))
5259 (defun gnus-check-group-server ()
5260 ;; Make sure the connection to the server is alive.
5261 (unless (gnus-server-opened
5262 (gnus-find-method-for-group gnus-newsgroup-name))
5263 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
5264 (gnus-request-group gnus-newsgroup-name t)))
5267 (autoload 'nneething-get-file-name "nneething"))
5269 (defun gnus-request-article-this-buffer (article group)
5270 "Get an article and insert it into this buffer.
5271 T-gnus change: Insert an article into `gnus-original-article-buffer'."
5272 (let (do-update-line sparse-header)
5273 ;; The current buffer is `gnus-article-buffer'.
5277 (gnus-kill-all-overlays)
5278 (setq group (or group gnus-newsgroup-name))
5280 ;; Using `gnus-request-article' directly will insert the article into
5281 ;; `nntp-server-buffer' - so we'll save some time by not having to
5282 ;; copy it from the server buffer into the article buffer.
5284 ;; We only request an article by message-id when we do not have the
5285 ;; headers for it, so we'll have to get those.
5286 (when (stringp article)
5287 (gnus-read-header article))
5289 ;; If the article number is negative, that means that this article
5290 ;; doesn't belong in this newsgroup (possibly), so we find its
5291 ;; message-id and request it by id instead of number.
5292 (when (and (numberp article)
5294 (get-buffer gnus-summary-buffer)
5295 (gnus-buffer-exists-p gnus-summary-buffer))
5297 (set-buffer gnus-summary-buffer)
5298 (let ((header (gnus-summary-article-header article)))
5301 ((memq article gnus-newsgroup-sparse)
5302 ;; This is a sparse gap article.
5303 (setq do-update-line article)
5304 (setq article (mail-header-id header))
5305 (setq sparse-header (gnus-read-header article))
5306 (setq gnus-newsgroup-sparse
5307 (delq article gnus-newsgroup-sparse)))
5309 ;; It's a real article.
5310 (setq article (mail-header-id header)))
5312 ;; It is an extracted pseudo-article.
5313 (setq article 'pseudo)
5314 (gnus-request-pseudo-article header))))
5316 (let ((method (gnus-find-method-for-group
5317 gnus-newsgroup-name)))
5318 (when (and (eq (car method) 'nneething)
5320 (let ((dir (nneething-get-file-name
5321 (mail-header-id header))))
5322 (when (and (stringp dir)
5323 (file-directory-p dir))
5324 (setq article 'nneething)
5325 (gnus-group-enter-directory dir))))))))
5326 (setq gnus-original-article (cons group article))
5328 ;; The current buffer is `gnus-original-article-buffer'.
5329 (if (get-buffer gnus-original-article-buffer)
5330 (set-buffer gnus-original-article-buffer)
5331 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
5332 (set-buffer-multibyte nil)
5333 (buffer-disable-undo)
5334 (setq major-mode 'gnus-original-article-mode)
5335 (setq buffer-read-only nil))
5338 ;; Refuse to select canceled articles.
5339 ((and (numberp article)
5341 (get-buffer gnus-summary-buffer)
5342 (gnus-buffer-exists-p gnus-summary-buffer)
5343 (eq (cdr (save-excursion
5344 (set-buffer gnus-summary-buffer)
5345 (assq article gnus-newsgroup-reads)))
5346 gnus-canceled-mark))
5348 ;; Check the backlog.
5349 ((and gnus-keep-backlog
5350 (gnus-backlog-request-article group article (current-buffer)))
5352 ;; Check asynchronous pre-fetch.
5353 ((gnus-async-request-fetched-article group article (current-buffer))
5354 (gnus-async-prefetch-next group article gnus-summary-buffer)
5355 (when (and (numberp article) gnus-keep-backlog)
5356 (gnus-backlog-enter-article group article (current-buffer)))
5359 ((and gnus-use-cache
5361 (gnus-cache-request-article article group))
5363 ;; Check the agent cache.
5364 ((and gnus-agent gnus-agent-cache gnus-plugged
5366 (gnus-agent-request-article article group))
5368 ;; Get the article and put into the article buffer.
5369 ((or (stringp article)
5371 (let ((gnus-override-method gnus-override-method)
5372 (methods (and (stringp article)
5373 gnus-refer-article-method))
5375 (buffer-read-only nil))
5376 (if (or (not (listp methods))
5377 (and (symbolp (car methods))
5378 (assq (car methods) nnoo-definition-alist)))
5379 (setq methods (list methods)))
5380 (when (and (null gnus-override-method)
5382 (setq gnus-override-method (pop methods)))
5384 (when (eq gnus-override-method 'current)
5385 (setq gnus-override-method
5386 (with-current-buffer gnus-summary-buffer
5387 gnus-current-select-method)))
5389 (gnus-kill-all-overlays)
5390 (let ((gnus-newsgroup-name group))
5391 (gnus-check-group-server))
5392 (when (gnus-request-article article group (current-buffer))
5393 (when (numberp article)
5394 (gnus-async-prefetch-next group article
5395 gnus-summary-buffer)
5396 (when gnus-keep-backlog
5397 (gnus-backlog-enter-article
5398 group article (current-buffer))))
5399 (setq result 'article))
5402 (setq gnus-override-method (pop methods))
5403 (setq result 'done))))
5404 (and (eq result 'article) 'article)))
5408 ;; Associate this article with the current summary buffer.
5409 (setq gnus-article-current-summary gnus-summary-buffer)
5411 ;; Copy the requested article from `gnus-original-article-buffer'.
5412 (unless (equal (buffer-name (current-buffer))
5413 (buffer-name (get-buffer gnus-original-article-buffer)))
5414 (insert-buffer gnus-original-article-buffer))
5417 (run-hooks 'gnus-article-decode-hook)
5418 ;; Mark article as decoded or not.
5419 (setq gnus-article-decoded-p gnus-article-decode-hook)
5421 ;; Update sparse articles.
5422 (when (and do-update-line
5423 (or (numberp article)
5425 (let ((buf (current-buffer)))
5426 (set-buffer gnus-summary-buffer)
5427 (gnus-summary-update-article do-update-line sparse-header)
5428 (gnus-summary-goto-subject do-update-line nil t)
5429 (set-window-point (gnus-get-buffer-window (current-buffer) t)
5431 (set-buffer buf))))))
5437 (defcustom gnus-article-edit-mode-hook nil
5438 "Hook run in article edit mode buffers."
5439 :group 'gnus-article-various
5442 (defcustom gnus-article-edit-article-setup-function
5443 'gnus-article-mime-edit-article-setup
5444 "Function called to setup an editing article buffer."
5445 :group 'gnus-article-various
5448 (defvar gnus-article-edit-done-function nil)
5450 (defvar gnus-article-edit-mode-map nil)
5452 ;; Should we be using derived.el for this?
5453 (unless gnus-article-edit-mode-map
5454 (setq gnus-article-edit-mode-map (make-sparse-keymap))
5455 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
5457 (gnus-define-keys gnus-article-edit-mode-map
5458 "\C-c\C-c" gnus-article-edit-done
5459 "\C-c\C-k" gnus-article-edit-exit)
5461 (gnus-define-keys (gnus-article-edit-wash-map
5462 "\C-c\C-w" gnus-article-edit-mode-map)
5463 "f" gnus-article-edit-full-stops))
5465 (define-derived-mode gnus-article-edit-mode text-mode "Article Edit"
5466 "Major mode for editing articles.
5467 This is an extended text-mode.
5469 \\{gnus-article-edit-mode-map}"
5470 (make-local-variable 'gnus-article-edit-done-function)
5471 (make-local-variable 'gnus-prev-winconf)
5472 (set (make-local-variable 'font-lock-defaults)
5473 '(message-font-lock-keywords t))
5474 (setq buffer-read-only nil)
5475 (buffer-enable-undo)
5478 (defun gnus-article-edit (&optional force)
5479 "Edit the current article.
5480 This will have permanent effect only in mail groups.
5481 If FORCE is non-nil, allow editing of articles even in read-only
5484 (when (and (not force)
5485 (gnus-group-read-only-p))
5486 (error "The current newsgroup does not support article editing"))
5487 (gnus-article-date-original)
5488 (gnus-article-edit-article
5490 `(lambda (no-highlight)
5492 (gnus-summary-edit-article-done
5493 ,(or (mail-header-references gnus-current-headers) "")
5494 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
5496 (defun gnus-article-edit-article (start-func exit-func)
5497 "Start editing the contents of the current article buffer."
5498 (let ((winconf (current-window-configuration)))
5499 (set-buffer gnus-article-buffer)
5500 (gnus-article-edit-mode)
5501 (funcall start-func)
5502 (set-buffer-modified-p nil)
5503 (gnus-configure-windows 'edit-article)
5504 (setq gnus-article-edit-done-function exit-func)
5505 (setq gnus-prev-winconf winconf)
5506 (when gnus-article-edit-article-setup-function
5507 (funcall gnus-article-edit-article-setup-function))
5508 (gnus-message 6 "C-c C-c to end edits; C-c C-k to exit")))
5510 (defun gnus-article-edit-done (&optional arg)
5511 "Update the article edits and exit."
5513 (let ((func gnus-article-edit-done-function)
5514 (buf (current-buffer))
5515 (start (window-start)))
5516 (remove-hook 'gnus-article-mode-hook
5517 'gnus-article-mime-edit-article-unwind)
5518 ;; We remove all text props from the article buffer.
5520 (buffer-substring-no-properties (point-min) (point-max)))
5524 (let ((winconf gnus-prev-winconf))
5526 (set-window-configuration winconf)
5527 ;; Tippy-toe some to make sure that point remains where it was.
5528 (save-current-buffer
5530 (set-window-start (get-buffer-window (current-buffer)) start)
5534 (let ((buffer-read-only nil))
5536 ;; The cache and backlog have to be flushed somewhat.
5537 (when gnus-keep-backlog
5538 (gnus-backlog-remove-article
5539 (car gnus-article-current) (cdr gnus-article-current)))
5540 ;; Flush original article as well.
5542 (when (get-buffer gnus-original-article-buffer)
5543 (set-buffer gnus-original-article-buffer)
5544 (setq gnus-original-article nil)))
5545 (when gnus-use-cache
5546 (gnus-cache-update-article
5547 (car gnus-article-current) (cdr gnus-article-current))))
5549 (set-window-start (get-buffer-window buf) start)
5550 (set-window-point (get-buffer-window buf) (point))))
5552 (defun gnus-article-edit-exit ()
5553 "Exit the article editing without updating."
5555 (when (or (not (buffer-modified-p))
5556 (yes-or-no-p "Article modified; kill anyway? "))
5557 (let ((curbuf (current-buffer))
5559 (window-start (window-start)))
5561 (if (gnus-buffer-live-p gnus-original-article-buffer)
5562 (insert-buffer gnus-original-article-buffer))
5563 (let ((winconf gnus-prev-winconf))
5565 (set-window-configuration winconf)
5566 ;; Tippy-toe some to make sure that point remains where it was.
5567 (save-current-buffer
5569 (set-window-start (get-buffer-window (current-buffer)) window-start)
5572 (defun gnus-article-edit-full-stops ()
5573 "Interactively repair spacing at end of sentences."
5576 (goto-char (point-min))
5577 (search-forward-regexp "^$" nil t)
5578 (let ((case-fold-search nil))
5579 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
5582 ;;; Article editing with MIME-Edit
5585 (defcustom gnus-article-mime-edit-article-setup-hook nil
5586 "Hook run after setting up a MIME editing article buffer."
5587 :group 'gnus-article-various
5590 (defun gnus-article-mime-edit-article-unwind ()
5591 "Unwind `gnus-article-buffer' if article editing was given up."
5592 (remove-hook 'gnus-article-mode-hook 'gnus-article-mime-edit-article-unwind)
5593 (when (featurep 'font-lock)
5594 (setq font-lock-defaults nil)
5595 (font-lock-mode -1))
5596 (when mime-edit-mode-flag
5597 (mime-edit-exit 'nomime 'no-error)
5600 (defun gnus-article-mime-edit-article-setup ()
5601 "Convert current buffer to MIME-Edit buffer and turn on MIME-Edit mode
5602 after replacing with the original article."
5603 (setq gnus-show-mime t)
5604 (setq gnus-article-edit-done-function
5605 `(lambda (&rest args)
5606 (when mime-edit-mode-flag
5607 (let (mime-edit-insert-user-agent-field)
5610 (goto-char (point-min))
5611 (let (case-fold-search)
5612 (when (re-search-forward
5613 (format "^%s$" (regexp-quote mail-header-separator))
5615 (replace-match "")))
5616 (apply ,gnus-article-edit-done-function args)
5619 (buffer-substring-no-properties (point-min) (point-max))
5620 (set-buffer (get-buffer-create gnus-original-article-buffer))
5622 (setq gnus-current-headers (gnus-article-make-full-mail-header))
5623 (set-buffer gnus-article-buffer)
5624 (gnus-article-prepare-display)))
5625 (substitute-key-definition 'gnus-article-edit-done
5626 'gnus-article-mime-edit-done
5627 gnus-article-edit-mode-map)
5628 (substitute-key-definition 'gnus-article-edit-exit
5629 'gnus-article-mime-edit-exit
5630 gnus-article-edit-mode-map)
5632 (insert-buffer gnus-original-article-buffer)
5633 (let ((ofn (symbol-function 'mime-edit-decode-single-part-in-buffer)))
5634 (fset 'mime-edit-decode-single-part-in-buffer
5635 (lambda (&rest args)
5636 (if (let ((content-type (car args)))
5637 (and (eq 'message (mime-content-type-primary-type
5639 (eq 'rfc822 (mime-content-type-subtype content-type))))
5640 (setcar (cdr args) 'not-decode-text))
5644 (fset 'mime-edit-decode-single-part-in-buffer ofn)))
5645 (when (featurep 'font-lock)
5646 (set (make-local-variable 'font-lock-defaults)
5647 '(message-font-lock-keywords t))
5648 (font-lock-set-defaults)
5649 (turn-on-font-lock))
5650 (set-buffer-modified-p nil)
5651 (delete-other-windows)
5652 (add-hook 'gnus-article-mode-hook 'gnus-article-mime-edit-article-unwind)
5653 (gnus-run-hooks 'gnus-article-mime-edit-article-setup-hook))
5655 (defun gnus-article-mime-edit-done (&optional arg)
5656 "Update the article MIME edits and exit."
5658 (when (featurep 'font-lock)
5659 (setq font-lock-defaults nil)
5660 (font-lock-mode -1))
5661 (gnus-article-edit-done arg))
5663 (defun gnus-article-mime-edit-exit ()
5664 "Exit the article MIME editing without updating."
5666 (when (or (not (buffer-modified-p))
5667 (yes-or-no-p "Article modified; kill anyway? "))
5668 (when (featurep 'font-lock)
5669 (setq font-lock-defaults nil)
5670 (font-lock-mode -1))
5671 (when mime-edit-mode-flag
5672 (let (mime-edit-insert-user-agent-field)
5675 (goto-char (point-min))
5676 (let (case-fold-search)
5677 (when (re-search-forward
5678 (format "^%s$" (regexp-quote mail-header-separator)) nil t)
5679 (replace-match "")))
5680 (let ((winconf gnus-prev-winconf))
5682 (buffer-substring-no-properties (point-min) (point-max))
5683 (set-buffer (get-buffer-create gnus-original-article-buffer))
5685 (setq gnus-current-headers (gnus-article-make-full-mail-header))
5686 (set-buffer gnus-article-buffer)
5687 (gnus-article-prepare-display)
5688 (set-window-configuration winconf))))
5691 ;;; Article highlights
5694 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
5696 ;;; Internal Variables:
5698 (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\\)\\)"
5699 "Regular expression that matches URLs."
5700 :group 'gnus-article-buttons
5703 (defcustom gnus-button-alist
5704 `(("<\\(url:[>\n\t ]*?\\)?\\(nntp\\|news\\):[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
5705 0 t gnus-button-handle-news 3)
5706 ("\\b\\(nntp\\|news\\):\\([^>\n\t ]*@[^>)!;:,\n\t ]*\\)" 0 t
5707 gnus-button-handle-news 2)
5708 ("\\(\\b<\\(url:[>\n\t ]*\\)?news:[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
5710 gnus-button-fetch-group 4)
5711 ("\\bnews:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
5712 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
5713 t gnus-button-message-id 3)
5714 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 2)
5715 ("mailto:\\([-a-zA-Z.@_+0-9%=?]+\\)" 0 t gnus-url-mailto 1)
5716 ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 1)
5718 ("\\binfo:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t
5719 gnus-button-handle-info 2)
5720 ;; This is how URLs _should_ be embedded in text...
5721 ("<URL: *\\([^<>]*\\)>" 1 t gnus-button-embedded-url 1)
5723 (,gnus-button-url-regexp 0 t browse-url 0))
5724 "*Alist of regexps matching buttons in article bodies.
5726 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
5727 REGEXP: is the string matching text around the button,
5728 BUTTON: is the number of the regexp grouping actually matching the button,
5729 FORM: is a lisp expression which must eval to true for the button to
5731 CALLBACK: is the function to call when the user push this button, and each
5732 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
5734 CALLBACK can also be a variable, in that case the value of that
5735 variable it the real callback function."
5736 :group 'gnus-article-buttons
5737 :type '(repeat (list regexp
5738 (integer :tag "Button")
5740 (function :tag "Callback")
5743 (integer :tag "Regexp group")))))
5745 (defcustom gnus-header-button-alist
5746 `(("^\\(References\\|Message-I[Dd]\\):" "<[^<>]+>"
5747 0 t gnus-button-message-id 0)
5748 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
5749 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
5750 0 t gnus-button-mailto 0)
5751 ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t browse-url 0)
5752 ("^Subject:" ,gnus-button-url-regexp 0 t browse-url 0)
5753 ("^[^:]+:" ,gnus-button-url-regexp 0 t browse-url 0)
5754 ("^[^:]+:" "\\bmailto:\\([-a-zA-Z.@_+0-9%=?]+\\)" 0 t gnus-url-mailto 1)
5755 ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
5756 gnus-button-message-id 3))
5757 "*Alist of headers and regexps to match buttons in article heads.
5759 This alist is very similar to `gnus-button-alist', except that each
5760 alist has an additional HEADER element first in each entry:
5762 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
5764 HEADER is a regexp to match a header. For a fuller explanation, see
5765 `gnus-button-alist'."
5766 :group 'gnus-article-buttons
5767 :group 'gnus-article-headers
5768 :type '(repeat (list (regexp :tag "Header")
5770 (integer :tag "Button")
5772 (function :tag "Callback")
5775 (integer :tag "Regexp group")))))
5777 (defvar gnus-button-regexp nil)
5778 (defvar gnus-button-marker-list nil)
5779 ;; Regexp matching any of the regexps from `gnus-button-alist'.
5781 (defvar gnus-button-last nil)
5782 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
5786 (defun gnus-article-push-button (event)
5787 "Check text under the mouse pointer for a callback function.
5788 If the text under the mouse pointer has a `gnus-callback' property,
5789 call it with the value of the `gnus-data' text property."
5791 (set-buffer (window-buffer (posn-window (event-start event))))
5792 (let* ((pos (posn-point (event-start event)))
5793 (data (get-text-property pos 'gnus-data))
5794 (fun (get-text-property pos 'gnus-callback)))
5797 (funcall fun data))))
5799 (defun gnus-article-press-button ()
5800 "Check text at point for a callback function.
5801 If the text at point has a `gnus-callback' property,
5802 call it with the value of the `gnus-data' text property."
5804 (let* ((data (get-text-property (point) 'gnus-data))
5805 (fun (get-text-property (point) 'gnus-callback)))
5807 (funcall fun data))))
5809 (defun gnus-article-prev-button (n)
5810 "Move point to N buttons backward.
5811 If N is negative, move forward instead."
5813 (gnus-article-next-button (- n)))
5815 (defun gnus-article-next-button (n)
5816 "Move point to N buttons forward.
5817 If N is negative, move backward instead."
5819 (let ((function (if (< n 0) 'previous-single-property-change
5820 'next-single-property-change))
5821 (inhibit-point-motion-hooks t)
5823 (limit (if (< n 0) (point-min) (point-max))))
5825 (while (and (not (= limit (point)))
5827 ;; Skip past the current button.
5828 (when (get-text-property (point) 'gnus-callback)
5829 (goto-char (funcall function (point) 'gnus-callback nil limit)))
5830 ;; Go to the next (or previous) button.
5831 (gnus-goto-char (funcall function (point) 'gnus-callback nil limit))
5832 ;; Put point at the start of the button.
5833 (when (and backward (not (get-text-property (point) 'gnus-callback)))
5834 (goto-char (funcall function (point) 'gnus-callback nil limit)))
5835 ;; Skip past intangible buttons.
5836 (when (get-text-property (point) 'intangible)
5840 (gnus-message 5 "No more buttons"))
5843 (defun gnus-article-highlight (&optional force)
5844 "Highlight current article.
5845 This function calls `gnus-article-highlight-headers',
5846 `gnus-article-highlight-citation',
5847 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
5848 do the highlighting. See the documentation for those functions."
5849 (interactive (list 'force))
5850 (gnus-article-highlight-headers)
5851 (gnus-article-highlight-citation force)
5852 (gnus-article-highlight-signature)
5853 (gnus-article-add-buttons force)
5854 (gnus-article-add-buttons-to-head))
5856 (defun gnus-article-highlight-some (&optional force)
5857 "Highlight current article.
5858 This function calls `gnus-article-highlight-headers',
5859 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
5860 do the highlighting. See the documentation for those functions."
5861 (interactive (list 'force))
5862 (gnus-article-highlight-headers)
5863 (gnus-article-highlight-signature)
5864 (gnus-article-add-buttons))
5866 (defun gnus-article-highlight-headers ()
5867 "Highlight article headers as specified by `gnus-header-face-alist'."
5870 (set-buffer gnus-article-buffer)
5872 (let ((alist gnus-header-face-alist)
5873 (buffer-read-only nil)
5874 (case-fold-search t)
5875 (inhibit-point-motion-hooks t)
5876 entry regexp header-face field-face from hpoints fpoints)
5877 (article-narrow-to-head)
5878 (while (setq entry (pop alist))
5879 (goto-char (point-min))
5880 (setq regexp (concat "^\\("
5881 (if (string-equal "" (nth 0 entry))
5885 header-face (nth 1 entry)
5886 field-face (nth 2 entry))
5887 (while (and (re-search-forward regexp nil t)
5891 (unless (search-forward ":" nil t)
5893 (when (and header-face
5894 (not (memq (point) hpoints)))
5895 (push (point) hpoints)
5896 (gnus-put-text-property from (point) 'face header-face))
5897 (when (and field-face
5898 (not (memq (setq from (point)) fpoints)))
5900 (if (re-search-forward "^[^ \t]" nil t)
5902 (goto-char (point-max)))
5903 (gnus-put-text-property from (point) 'face field-face))))))))
5905 (defun gnus-article-highlight-signature ()
5906 "Highlight the signature in an article.
5907 It does this by highlighting everything after
5908 `gnus-signature-separator' using `gnus-signature-face'."
5910 (when gnus-signature-face
5912 (set-buffer gnus-article-buffer)
5913 (let ((buffer-read-only nil)
5914 (inhibit-point-motion-hooks t))
5916 (when (gnus-article-narrow-to-signature)
5917 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
5918 'face gnus-signature-face)))))))
5920 (defun gnus-article-buttonize-signature ()
5921 "Add button to the signature."
5924 (set-buffer gnus-article-buffer)
5925 (let ((buffer-read-only nil)
5926 (inhibit-point-motion-hooks t))
5927 (when (gnus-article-search-signature)
5928 (gnus-article-add-button (match-beginning 0) (match-end 0)
5929 'gnus-signature-toggle
5930 (set-marker (make-marker)
5931 (1+ (match-end 0))))))))
5933 (defun gnus-button-in-region-p (b e prop)
5934 "Say whether PROP exists in the region."
5935 (text-property-not-all b e prop nil))
5937 (defun gnus-article-add-buttons (&optional force)
5938 "Find external references in the article and make buttons of them.
5939 \"External references\" are things like Message-IDs and URLs, as
5940 specified by `gnus-button-alist'."
5941 (interactive (list 'force))
5943 (set-buffer gnus-article-buffer)
5944 (let ((buffer-read-only nil)
5945 (inhibit-point-motion-hooks t)
5946 (case-fold-search t)
5947 (alist gnus-button-alist)
5949 ;; Remove all old markers.
5950 (let (marker entry new-list)
5951 (while (setq marker (pop gnus-button-marker-list))
5952 (if (or (< marker (point-min)) (>= marker (point-max)))
5953 (push marker new-list)
5955 (when (setq entry (gnus-button-entry))
5956 (put-text-property (match-beginning (nth 1 entry))
5957 (match-end (nth 1 entry))
5958 'gnus-callback nil))
5959 (set-marker marker nil)))
5960 (setq gnus-button-marker-list new-list))
5961 ;; We skip the headers.
5964 (while (setq entry (pop alist))
5965 (setq regexp (car entry))
5967 (while (re-search-forward regexp nil t)
5968 (let* ((start (and entry (match-beginning (nth 1 entry))))
5969 (end (and entry (match-end (nth 1 entry))))
5970 (from (match-beginning 0)))
5971 (when (and (or (eq t (nth 2 entry))
5972 (eval (nth 2 entry)))
5973 (not (gnus-button-in-region-p
5974 start end 'gnus-callback)))
5975 ;; That optional form returned non-nil, so we add the
5977 (gnus-article-add-button
5978 start end 'gnus-button-push
5979 (car (push (set-marker (make-marker) from)
5980 gnus-button-marker-list))))))))))
5982 ;; Add buttons to the head of an article.
5983 (defun gnus-article-add-buttons-to-head ()
5984 "Add buttons to the head of the article."
5987 (set-buffer gnus-article-buffer)
5989 (let ((buffer-read-only nil)
5990 (inhibit-point-motion-hooks t)
5991 (case-fold-search t)
5992 (alist gnus-header-button-alist)
5994 (article-narrow-to-head)
5996 ;; Each alist entry.
5997 (setq entry (car alist)
5999 (goto-char (point-min))
6000 (while (re-search-forward (car entry) nil t)
6001 ;; Each header matching the entry.
6002 (setq beg (match-beginning 0))
6003 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
6004 (match-beginning 0))
6007 (while (re-search-forward (nth 1 entry) end t)
6008 ;; Each match within a header.
6009 (let* ((entry (cdr entry))
6010 (start (match-beginning (nth 1 entry)))
6011 (end (match-end (nth 1 entry)))
6012 (form (nth 2 entry)))
6013 (goto-char (match-end 0))
6015 (gnus-article-add-button
6016 start end (nth 3 entry)
6017 (buffer-substring (match-beginning (nth 4 entry))
6018 (match-end (nth 4 entry)))))))
6019 (goto-char end)))))))
6021 ;;; External functions:
6023 (defun gnus-article-add-button (from to fun &optional data)
6024 "Create a button between FROM and TO with callback FUN and data DATA."
6025 (when gnus-article-button-face
6026 (gnus-overlay-put (gnus-make-overlay from to)
6027 'face gnus-article-button-face))
6028 (gnus-add-text-properties
6030 (nconc (and gnus-article-mouse-face
6031 (list gnus-mouse-face-prop gnus-article-mouse-face))
6032 (list 'gnus-callback fun)
6033 (and data (list 'gnus-data data))))
6034 (widget-convert-button 'link from to :action 'gnus-widget-press-button
6035 ;; Quote `:button-keymap' for Mule 2.3
6036 ;; but it won't work.
6037 ':button-keymap gnus-widget-button-keymap))
6039 ;;; Internal functions:
6041 (defun gnus-article-set-globals ()
6043 (set-buffer gnus-summary-buffer)
6044 (gnus-set-global-variables)))
6046 (defun gnus-signature-toggle (end)
6048 (set-buffer gnus-article-buffer)
6049 (let ((buffer-read-only nil)
6050 (inhibit-point-motion-hooks t)
6051 (limit (next-single-property-change end 'mime-view-entity
6053 (if (text-property-any end limit 'article-type 'signature)
6055 (gnus-delete-wash-type 'signature)
6056 (gnus-remove-text-properties-when
6057 'article-type 'signature end limit
6058 (cons 'article-type (cons 'signature
6059 gnus-hidden-properties))))
6060 (gnus-add-wash-type 'signature)
6061 (gnus-add-text-properties-when
6062 'article-type nil end limit
6063 (cons 'article-type (cons 'signature
6064 gnus-hidden-properties)))))
6065 (let ((gnus-article-mime-handle-alist-1 gnus-article-mime-handle-alist))
6066 (gnus-set-mode-line 'article))))
6068 (defun gnus-button-entry ()
6069 ;; Return the first entry in `gnus-button-alist' matching this place.
6070 (let ((alist gnus-button-alist)
6073 (setq entry (pop alist))
6074 (if (looking-at (car entry))
6079 (defun gnus-button-push (marker)
6080 ;; Push button starting at MARKER.
6083 (let* ((entry (gnus-button-entry))
6084 (inhibit-point-motion-hooks t)
6086 (args (mapcar (lambda (group)
6087 (let ((string (match-string group)))
6088 (gnus-set-text-properties
6089 0 (length string) nil string)
6096 (fboundp (symbol-value fun)))
6097 (apply (symbol-value fun) args))
6099 (gnus-message 1 "You must define `%S' to use this button"
6100 (cons fun args)))))))
6102 (defun gnus-parse-news-url (url)
6103 (let (scheme server group message-id articles)
6106 (goto-char (point-min))
6107 (when (looking-at "\\([A-Za-z]+\\):")
6108 (setq scheme (match-string 1))
6109 (goto-char (match-end 0)))
6110 (when (looking-at "//\\([^/]+\\)/")
6111 (setq server (match-string 1))
6112 (goto-char (match-end 0)))
6115 ((looking-at "\\(.*@.*\\)")
6116 (setq message-id (match-string 1)))
6117 ((looking-at "\\([^/]+\\)/\\([-0-9]+\\)")
6118 (setq group (match-string 1)
6119 articles (split-string (match-string 2) "-")))
6120 ((looking-at "\\([^/]+\\)/?")
6121 (setq group (match-string 1)))
6123 (error "Unknown news URL syntax"))))
6124 (list scheme server group message-id articles)))
6126 (defun gnus-button-handle-news (url)
6128 (destructuring-bind (scheme server group message-id articles)
6129 (gnus-parse-news-url url)
6133 (set-buffer gnus-summary-buffer)
6135 (let ((gnus-refer-article-method (list (list 'nntp server))))
6136 (gnus-summary-refer-article message-id))
6137 (gnus-summary-refer-article message-id))))
6139 (gnus-button-fetch-group url)))))
6141 (defun gnus-button-handle-info (url)
6142 "Fetch an info URL."
6144 "^\\([^:/]+\\)?/\\(.*\\)"
6146 (gnus-info-find-node
6147 (concat "(" (or (gnus-url-unhex-string (match-string 1 url))
6150 (gnus-url-unhex-string (match-string 2 url))))
6151 (error "Can't parse %s" url)))
6153 (defun gnus-button-message-id (message-id)
6156 (set-buffer gnus-summary-buffer)
6157 (gnus-summary-refer-article message-id)))
6159 (defun gnus-button-fetch-group (address)
6160 "Fetch GROUP specified by ADDRESS."
6161 (if (not (string-match "[:/]" address))
6162 ;; This is just a simple group url.
6163 (gnus-group-read-ephemeral-group address gnus-select-method)
6166 "^\\([^:/]+\\)\\(:\\([^/]+\\)\\)?/\\([^/]+\\)\\(/\\([0-9]+\\)\\)?"
6168 (error "Can't parse %s" address)
6169 (gnus-group-read-ephemeral-group
6170 (match-string 4 address)
6171 `(nntp ,(match-string 1 address)
6172 (nntp-address ,(match-string 1 address))
6173 (nntp-port-number ,(if (match-end 3)
6174 (match-string 3 address)
6177 (and (match-end 6) (list (string-to-int (match-string 6 address))))))))
6179 (defun gnus-url-parse-query-string (query &optional downcase)
6180 (let (retval pairs cur key val)
6181 (setq pairs (split-string query "&"))
6183 (setq cur (car pairs)
6185 (if (not (string-match "=" cur))
6187 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
6188 val (gnus-url-unhex-string (substring cur (match-end 0) nil) t))
6190 (setq key (downcase key)))
6191 (setq cur (assoc key retval))
6193 (setcdr cur (cons val (cdr cur)))
6194 (setq retval (cons (list key val) retval)))))
6197 (defun gnus-url-mailto (url)
6198 ;; Send mail to someone
6199 (when (string-match "mailto:/*\\(.*\\)" url)
6200 (setq url (substring url (match-beginning 1) nil)))
6201 (let (to args subject func)
6202 (if (string-match (regexp-quote "?") url)
6203 (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
6204 args (gnus-url-parse-query-string
6205 (substring url (match-end 0) nil) t))
6206 (setq to (gnus-url-unhex-string url)))
6207 (setq args (cons (list "to" to) args)
6208 subject (cdr-safe (assoc "subject" args)))
6211 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
6214 (message-position-on-field (caar args)))
6215 (insert (mapconcat 'identity (cdar args) ", "))
6216 (setq args (cdr args)))
6219 (message-goto-subject))))
6221 (defun gnus-button-embedded-url (address)
6222 "Activate ADDRESS with `browse-url'."
6223 (browse-url (gnus-strip-whitespace address)))
6225 ;;; Next/prev buttons in the article buffer.
6227 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
6228 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
6230 (defvar gnus-prev-page-map
6231 (let ((map (make-sparse-keymap)))
6232 (unless (>= emacs-major-version 21)
6233 ;; XEmacs doesn't care.
6234 (set-keymap-parent map gnus-article-mode-map))
6235 (define-key map gnus-mouse-2 'gnus-button-prev-page)
6236 (define-key map "\r" 'gnus-button-prev-page)
6239 (defun gnus-insert-prev-page-button ()
6241 (buffer-read-only nil)
6242 (situation (get-text-property (point-min) 'mime-view-situation)))
6244 gnus-prev-page-line-format nil
6245 `(,@(gnus-local-map-property gnus-prev-page-map)
6247 gnus-callback gnus-article-button-prev-page
6248 article-type annotation
6249 mime-view-situation ,situation))
6250 (widget-convert-button
6252 :action 'gnus-button-prev-page
6253 :button-keymap gnus-prev-page-map)))
6255 (defvar gnus-next-page-map
6256 (let ((map (make-sparse-keymap)))
6257 (unless (>= emacs-major-version 21)
6258 ;; XEmacs doesn't care.
6259 (set-keymap-parent map gnus-article-mode-map))
6260 (define-key map gnus-mouse-2 'gnus-button-next-page)
6261 (define-key map "\r" 'gnus-button-next-page)
6264 (defun gnus-button-next-page (&optional args more-args)
6265 "Go to the next page."
6267 (let ((win (selected-window)))
6268 (select-window (gnus-get-buffer-window gnus-article-buffer t))
6269 (gnus-article-next-page)
6270 (select-window win)))
6272 (defun gnus-button-prev-page (&optional args more-args)
6273 "Go to the prev page."
6275 (let ((win (selected-window)))
6276 (select-window (gnus-get-buffer-window gnus-article-buffer t))
6277 (gnus-article-prev-page)
6278 (select-window win)))
6280 (defun gnus-insert-next-page-button ()
6282 (buffer-read-only nil)
6283 (situation (get-text-property (point-min) 'mime-view-situation)))
6284 (gnus-eval-format gnus-next-page-line-format nil
6285 `(,@(gnus-local-map-property gnus-next-page-map)
6287 gnus-callback gnus-article-button-next-page
6288 article-type annotation
6289 mime-view-situation ,situation))
6290 (widget-convert-button
6292 :action 'gnus-button-next-page
6293 :button-keymap gnus-next-page-map)))
6295 (defun gnus-article-button-next-page (arg)
6296 "Go to the next page."
6298 (let ((win (selected-window)))
6299 (select-window (gnus-get-buffer-window gnus-article-buffer t))
6300 (gnus-article-next-page)
6301 (select-window win)))
6303 (defun gnus-article-button-prev-page (arg)
6304 "Go to the prev page."
6306 (let ((win (selected-window)))
6307 (select-window (gnus-get-buffer-window gnus-article-buffer t))
6308 (gnus-article-prev-page)
6309 (select-window win)))
6311 (defvar gnus-decode-header-methods
6312 '(mail-decode-encoded-word-region)
6313 "List of methods used to decode headers.
6315 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
6316 is FUNCTION, FUNCTION will be apply to all newsgroups. If item is a
6317 \(REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
6318 whose names match REGEXP.
6321 \((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
6322 mail-decode-encoded-word-region
6323 (\"chinese\" . rfc1843-decode-region))
6326 (defvar gnus-decode-header-methods-cache nil)
6328 (defun gnus-multi-decode-header (start end)
6329 "Apply the functions from `gnus-encoded-word-methods' that match."
6330 (unless (and gnus-decode-header-methods-cache
6331 (eq gnus-newsgroup-name
6332 (car gnus-decode-header-methods-cache)))
6333 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
6336 (nconc gnus-decode-header-methods-cache (list x))
6337 (if (and gnus-newsgroup-name
6338 (string-match (car x) gnus-newsgroup-name))
6339 (nconc gnus-decode-header-methods-cache
6341 gnus-decode-header-methods))
6342 (let ((xlist gnus-decode-header-methods-cache))
6345 (narrow-to-region start end)
6347 (funcall (pop xlist) (point-min) (point-max))))))
6350 ;;; Treatment top-level handling.
6353 (defun gnus-treat-article (condition &optional part-number total-parts type)
6354 (let ((length (- (point-max) (point-min)))
6355 (alist gnus-treatment-function-alist)
6356 (article-goto-body-goes-to-point-min-p t)
6360 (let ((list gnus-article-treat-types))
6362 (when (string-match (pop list) type)
6363 (throw 'found t)))))))
6364 (highlightp (gnus-visual-p 'article-highlight 'highlight))
6365 (entity (static-unless (featurep 'xemacs)
6366 (when (eq 'head condition)
6367 (get-text-property (point-min) 'mime-view-entity))))
6368 val elem buttonized)
6369 (gnus-run-hooks 'gnus-part-display-hook)
6370 (unless gnus-inhibit-treatment
6371 (while (setq elem (pop alist))
6374 (if (gnus-buffer-live-p gnus-summary-buffer)
6375 (set-buffer gnus-summary-buffer))
6376 (symbol-value (car elem))))
6377 (when (and (or (consp val)
6379 (gnus-treat-predicate val)
6380 (or (not (get (car elem) 'highlight))
6382 (when (and (not buttonized)
6384 '(gnus-treat-hide-signature
6385 gnus-treat-highlight-signature)))
6386 (gnus-article-buttonize-signature)
6387 (setq buttonized t))
6389 (funcall (cadr elem)))))
6390 ;; FSF Emacsen does not inherit the existing text properties
6391 ;; in the new text, so we should do it for `mime-view-entity'.
6392 (static-unless (featurep 'xemacs)
6394 (put-text-property (point-min) (point-max)
6395 'mime-view-entity entity))))))
6397 ;; Dynamic variables.
6399 (defvar part-number)
6400 (defvar total-parts)
6405 (defun gnus-treat-predicate (val)
6410 (stringp (car val)))
6411 (apply 'gnus-or (mapcar `(lambda (s)
6412 (string-match s ,(or gnus-newsgroup-name "")))
6415 (let ((pred (pop val)))
6418 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
6420 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
6422 (not (gnus-treat-predicate (car val))))
6424 (equal (car val) type))
6426 (error "%S is not a valid predicate" pred)))))
6436 (eq part-number total-parts))
6440 (error "%S is not a valid value" val))))
6442 (defun gnus-article-encrypt-body (protocol &optional n)
6443 "Encrypt the article body."
6446 (or gnus-article-encrypt-protocol
6447 (completing-read "Encrypt protocol: "
6448 gnus-article-encrypt-protocol-alist
6450 current-prefix-arg))
6451 (let ((func (cdr (assoc protocol gnus-article-encrypt-protocol-alist))))
6453 (error (format "Can't find the encrypt protocol %s" protocol)))
6454 (if (equal gnus-newsgroup-name "nndraft:drafts")
6455 (error "Can't encrypt the article in group nndraft:drafts"))
6456 (if (equal gnus-newsgroup-name "nndraft:queue")
6457 (error "Don't encrypt the article in group nndraft:queue"))
6458 (gnus-summary-iterate n
6460 (set-buffer gnus-summary-buffer)
6461 (let ((mail-parse-charset gnus-newsgroup-charset)
6462 (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
6463 (summary-buffer gnus-summary-buffer)
6465 (gnus-set-global-variables)
6466 (when (gnus-group-read-only-p)
6467 (error "The current newsgroup does not support article encrypt"))
6468 (gnus-summary-show-article t)
6470 (or (mail-header-references gnus-current-headers) ""))
6471 (set-buffer gnus-article-buffer)
6472 (let* ((buffer-read-only nil)
6474 (mapcar (lambda (field)
6475 (and (save-restriction
6476 (message-narrow-to-head)
6477 (goto-char (point-min))
6478 (search-forward field nil t))
6480 (message-narrow-to-field)
6481 (buffer-substring (point-min) (point-max))
6482 (delete-region (point-min) (point-max))
6484 '("Content-Type:" "Content-Transfer-Encoding:"
6485 "Content-Disposition:"))))
6486 (message-narrow-to-head)
6487 (message-remove-header "MIME-Version")
6488 (goto-char (point-max))
6489 (setq point (point))
6490 (insert (apply 'concat headers))
6492 (narrow-to-region point (point-max))
6493 (let ((message-options message-options))
6494 (message-options-set 'message-sender user-mail-address)
6495 (message-options-set 'message-recipients user-mail-address)
6496 (message-options-set 'message-sign-encrypt 'not)
6498 (goto-char (point-min))
6499 (insert "MIME-Version: 1.0\n")
6501 (gnus-summary-edit-article-done
6502 references nil summary-buffer t))
6503 (when gnus-keep-backlog
6504 (gnus-backlog-remove-article
6505 (car gnus-article-current) (cdr gnus-article-current)))
6507 (when (get-buffer gnus-original-article-buffer)
6508 (set-buffer gnus-original-article-buffer)
6509 (setq gnus-original-article nil)))
6510 (when gnus-use-cache
6511 (gnus-cache-update-article
6512 (car gnus-article-current) (cdr gnus-article-current))))))))
6514 (defvar gnus-mime-security-button-line-format "%{%([[%t:%i]%D]%)%}\n"
6515 "The following specs can be used:
6516 %t The security MIME type
6519 %D Details if button is pressed")
6521 (defvar gnus-mime-security-button-end-line-format "%{%([[End of %t]%D]%)%}\n"
6522 "The following specs can be used:
6523 %t The security MIME type
6526 %D Details if button is pressed")
6528 (defvar gnus-mime-security-button-line-format-alist
6529 '((?t gnus-tmp-type ?s)
6530 (?i gnus-tmp-info ?s)
6531 (?d gnus-tmp-details ?s)
6532 (?D gnus-tmp-pressed-details ?s)))
6534 (defvar gnus-mime-security-button-map
6535 (let ((map (make-sparse-keymap)))
6536 (unless (>= (string-to-number emacs-version) 21)
6537 (set-keymap-parent map gnus-article-mode-map))
6538 (define-key map gnus-mouse-2 'gnus-article-push-button)
6539 (define-key map "\r" 'gnus-article-press-button)
6542 (defvar gnus-mime-security-details-buffer nil)
6544 (defvar gnus-mime-security-button-pressed nil)
6546 (defvar gnus-mime-security-show-details-inline t
6547 "If non-nil, show details in the article buffer.")
6549 (defun gnus-mime-security-verify-or-decrypt (handle)
6550 (mm-remove-parts (cdr handle))
6551 (let ((region (mm-handle-multipart-ctl-parameter handle 'gnus-region))
6552 point buffer-read-only)
6554 (goto-char (car region)))
6556 (narrow-to-region (point) (point))
6557 (with-current-buffer (mm-handle-multipart-original-buffer handle)
6558 (let* ((mm-verify-option 'known)
6559 (mm-decrypt-option 'known)
6560 (nparts (mm-possibly-verify-or-decrypt (cdr handle) handle)))
6561 (unless (eq nparts (cdr handle))
6562 (mm-destroy-parts (cdr handle))
6563 (setcdr handle nparts))))
6564 (setq point (point))
6565 (gnus-mime-display-security handle)
6566 (goto-char (point-max)))
6568 (delete-region (point) (cdr region))
6569 (set-marker (car region) nil)
6570 (set-marker (cdr region) nil))
6573 (defun gnus-mime-security-show-details (handle)
6574 (let ((details (mm-handle-multipart-ctl-parameter handle 'gnus-details)))
6576 (if gnus-mime-security-show-details-inline
6577 (let ((gnus-mime-security-button-pressed t)
6578 (gnus-mime-security-button-line-format
6579 (get-text-property (point) 'gnus-line-format))
6582 (while (eq (get-text-property (point) 'gnus-line-format)
6583 gnus-mime-security-button-line-format)
6587 (narrow-to-region (point) (point))
6588 (gnus-insert-mime-security-button handle))
6589 (delete-region (point)
6590 (or (text-property-not-all
6593 gnus-mime-security-button-line-format)
6595 (if (gnus-buffer-live-p gnus-mime-security-details-buffer)
6596 (with-current-buffer gnus-mime-security-details-buffer
6599 (setq gnus-mime-security-details-buffer
6600 (gnus-get-buffer-create "*MIME Security Details*")))
6601 (with-current-buffer gnus-mime-security-details-buffer
6603 (goto-char (point-min)))
6604 (pop-to-buffer gnus-mime-security-details-buffer))
6605 (gnus-message 5 "No details."))))
6607 (defun gnus-mime-security-press-button (handle)
6608 (if (mm-handle-multipart-ctl-parameter handle 'gnus-info)
6609 (gnus-mime-security-show-details handle)
6610 (gnus-mime-security-verify-or-decrypt handle)))
6612 (defun gnus-insert-mime-security-button (handle &optional displayed)
6613 (let* ((protocol (mm-handle-multipart-ctl-parameter handle 'protocol))
6616 (or (nth 2 (assoc protocol mm-verify-function-alist))
6617 (nth 2 (assoc protocol mm-decrypt-function-alist))
6619 (if (equal (car handle) "multipart/signed")
6620 " Signed" " Encrypted")
6623 (or (mm-handle-multipart-ctl-parameter handle 'gnus-info)
6626 (mm-handle-multipart-ctl-parameter handle 'gnus-details))
6627 gnus-tmp-pressed-details
6629 (setq gnus-tmp-details
6630 (if gnus-tmp-details
6631 (concat "\n" gnus-tmp-details) ""))
6632 (setq gnus-tmp-pressed-details
6633 (if gnus-mime-security-button-pressed gnus-tmp-details ""))
6638 gnus-mime-security-button-line-format
6639 gnus-mime-security-button-line-format-alist
6640 `(,@(gnus-local-map-property gnus-mime-security-button-map)
6641 gnus-callback gnus-mime-security-press-button
6642 gnus-line-format ,gnus-mime-security-button-line-format
6643 article-type annotation
6646 (widget-convert-button
6649 :action 'gnus-widget-press-button
6650 :button-keymap gnus-mime-security-button-map
6652 (lambda (widget/window &optional overlay pos)
6653 ;; Needed to properly clear the message due to a bug in
6654 ;; wid-edit (XEmacs only).
6655 (if (boundp 'help-echo-owns-message)
6656 (setq help-echo-owns-message t))
6659 (aref gnus-mouse-2 0))))))
6661 (defun gnus-mime-display-security (handle)
6663 (narrow-to-region (point) (point))
6664 (unless (gnus-unbuttonized-mime-type-p (car handle))
6665 (gnus-insert-mime-security-button handle))
6666 (gnus-mime-display-mixed (cdr handle))
6669 (unless (gnus-unbuttonized-mime-type-p (car handle))
6670 (let ((gnus-mime-security-button-line-format
6671 gnus-mime-security-button-end-line-format))
6672 (gnus-insert-mime-security-button handle)))
6673 (mm-set-handle-multipart-parameter
6675 (cons (set-marker (make-marker) (point-min))
6676 (set-marker (make-marker) (point-max))))))
6682 (defun gnus-article-header-presentation-method (entity situation)
6683 (mime-insert-header entity)
6684 (article-decode-group-name))
6686 (set-alist 'mime-header-presentation-method-alist
6687 'gnus-original-article-mode
6688 #'gnus-article-header-presentation-method)
6690 (defun gnus-mime-preview-quitting-method ()
6691 (mime-preview-kill-buffer)
6692 (delete-other-windows)
6693 (gnus-article-show-summary)
6694 (gnus-summary-select-article gnus-show-all-headers t))
6696 (set-alist 'mime-preview-quitting-method-alist
6697 'gnus-original-article-mode #'gnus-mime-preview-quitting-method)
6699 (set-alist 'mime-preview-following-method-alist
6700 'gnus-original-article-mode #'gnus-following-method)
6702 (set-alist 'mime-preview-over-to-previous-method-alist
6703 'gnus-original-article-mode
6705 (if (> (point-min) 1)
6706 (gnus-article-prev-page)
6707 (gnus-article-read-summary-keys
6708 nil (gnus-character-to-event ?P)))))
6710 (set-alist 'mime-preview-over-to-next-method-alist
6711 'gnus-original-article-mode'
6713 (if (< (point-max) (buffer-size))
6714 (gnus-article-next-page)
6715 (gnus-article-read-summary-keys
6716 nil (gnus-character-to-event ?N)))))
6726 (run-hooks 'gnus-art-load-hook)
6728 ;;; gnus-art.el ends here