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-leading-whitespace nil
912 "Remove leading whitespace in headers.
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-hide-headers 'head
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-head-custom)
925 (defcustom gnus-treat-hide-boring-headers nil
926 "Hide boring headers.
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-signature nil
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-custom)
939 (defcustom gnus-treat-fill-article 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-hide-citation 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-maybe 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-strip-list-identifiers 'head
961 "Strip list identifiers from `gnus-list-identifiers`.
962 Valid values are nil, t, `head', `last', an integer or a predicate.
963 See Info node `(gnus)Customizing Articles' for details."
965 :group 'gnus-article-treat
966 :type gnus-article-treat-custom)
968 (defcustom gnus-treat-strip-pgp t
969 "Strip PGP signatures.
970 Valid values are nil, t, `head', `last', an integer or a predicate.
971 See Info node `(gnus)Customizing Articles' for details."
972 :group 'gnus-article-treat
973 :type gnus-article-treat-custom)
975 (defcustom gnus-treat-strip-pem nil
976 "Strip PEM 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-banner t
983 "Strip banners from articles.
984 The banner to be stripped is specified in the `banner' group parameter.
985 Valid values are nil, t, `head', `last', an integer or a predicate.
986 See Info node `(gnus)Customizing Articles' for details."
987 :group 'gnus-article-treat
988 :type gnus-article-treat-custom)
990 (defcustom gnus-treat-highlight-headers 'head
991 "Highlight the headers.
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-head-custom)
996 (put 'gnus-treat-highlight-headers 'highlight t)
998 (defcustom gnus-treat-highlight-citation t
999 "Highlight cited text.
1000 Valid values are nil, t, `head', `last', an integer or a predicate.
1001 See Info node `(gnus)Customizing Articles' for details."
1002 :group 'gnus-article-treat
1003 :type gnus-article-treat-custom)
1004 (put 'gnus-treat-highlight-citation 'highlight t)
1006 (defcustom gnus-treat-date-ut nil
1007 "Display the Date in UT (GMT).
1008 Valid values are nil, t, `head', `last', an integer or a predicate.
1009 See Info node `(gnus)Customizing Articles' for details."
1010 :group 'gnus-article-treat
1011 :type gnus-article-treat-head-custom)
1013 (defcustom gnus-treat-date-local nil
1014 "Display the Date in the local timezone.
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-english nil
1021 "Display the Date in a format that can be read aloud in English.
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-lapsed nil
1028 "Display the Date header in a way that says how much time has elapsed.
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-original nil
1035 "Display the date in the original timezone.
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-iso8601 nil
1042 "Display the date in the ISO8601 format.
1043 Valid values are nil, t, `head', `last', an integer or a predicate.
1044 See Info node `(gnus)Customizing Articles' for details."
1046 :group 'gnus-article-treat
1047 :type gnus-article-treat-head-custom)
1049 (defcustom gnus-treat-date-user-defined nil
1050 "Display the date in a user-defined format.
1051 The format is defined by the `gnus-article-time-format' variable.
1052 Valid values are nil, t, `head', `last', an integer or a predicate.
1053 See Info node `(gnus)Customizing Articles' for details."
1054 :group 'gnus-article-treat
1055 :type gnus-article-treat-head-custom)
1057 (defcustom gnus-treat-strip-headers-in-body t
1058 "Strip the X-No-Archive header line from the beginning of the body.
1059 Valid values are nil, t, `head', `last', an integer or a predicate.
1060 See Info node `(gnus)Customizing Articles' for details."
1062 :group 'gnus-article-treat
1063 :type gnus-article-treat-custom)
1065 (defcustom gnus-treat-strip-trailing-blank-lines nil
1066 "Strip trailing blank lines.
1067 Valid values are nil, t, `head', `last', an integer or a predicate.
1068 See Info node `(gnus)Customizing Articles' for details."
1069 :group 'gnus-article-treat
1070 :type gnus-article-treat-custom)
1072 (defcustom gnus-treat-strip-leading-blank-lines nil
1073 "Strip leading 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-multiple-blank-lines nil
1080 "Strip multiple 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-unfold-headers 'head
1087 "Unfold folded header 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-fold-headers nil
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-newsgroups 'head
1101 "Fold the Newsgroups and Followup-To headers.
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-overstrike t
1108 "Treat overstrike highlighting.
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)
1113 (put 'gnus-treat-overstrike 'highlight t)
1115 (defcustom gnus-treat-display-xface
1116 (and (or (and (fboundp 'image-type-available-p)
1117 (image-type-available-p 'xbm)
1118 (string-match "^0x" (shell-command-to-string "uncompface")))
1119 (and (featurep 'xemacs)
1121 (eq 'x-face-mule-gnus-article-display-x-face
1122 gnus-article-x-face-command))
1124 "Display X-Face headers.
1125 Valid values are nil, t, `head', `last', an integer or a predicate.
1126 See Info node `(gnus)Customizing Articles' and Info node
1127 `(gnus)X-Face' for details."
1128 :group 'gnus-article-treat
1130 :type gnus-article-treat-head-custom)
1131 (put 'gnus-treat-display-xface 'highlight t)
1133 (defcustom gnus-article-should-use-smiley-mule
1134 (not (or (featurep 'xemacs)
1135 (gnus-image-type-available-p 'xpm)
1136 (gnus-image-type-available-p 'pbm)))
1137 "If non-nil, gnus uses `smiley-mule' for displaying smileys rather than
1138 `smiley-ems'. It defaults to t when Emacs 20 or earlier is running.
1139 `smiley-mule' is boundled in BITMAP-MULE package. You can set it to t
1140 even if you are using Emacs 21+. It has no effect on XEmacs."
1141 :group 'gnus-article-various
1143 :get (lambda (symbol)
1144 (and (default-value symbol)
1145 (not (featurep 'xemacs))
1146 (module-installed-p 'smiley-mule)
1148 :set (lambda (symbol value)
1149 (set-default symbol (and value
1150 (not (featurep 'xemacs))
1151 (module-installed-p 'smiley-mule)
1154 (defvar gnus-article-smiley-mule-loaded-p nil
1155 "Internal variable used to say whether `smiley-mule' is loaded (whether
1156 smiley functions are not overridden by `smiley-ems').")
1158 (defcustom gnus-treat-display-smileys
1159 (if (or (and (featurep 'xemacs)
1161 (gnus-image-type-available-p 'xpm)
1162 (gnus-image-type-available-p 'pbm)
1163 (and (not (featurep 'xemacs))
1165 (module-installed-p 'smiley-mule)))
1169 Valid values are nil, t, `head', `last', an integer or a predicate.
1170 See Info node `(gnus)Customizing Articles' and Info node
1171 `(gnus)Smileys' for details."
1172 :group 'gnus-article-treat
1174 :type gnus-article-treat-custom)
1175 (put 'gnus-treat-display-smileys 'highlight t)
1177 (defcustom gnus-treat-from-picon
1178 (if (and (gnus-image-type-available-p 'xpm)
1179 (gnus-picons-installed-p))
1181 "Display picons in the From header.
1182 Valid values are nil, t, `head', `last', an integer or a predicate.
1183 See Info node `(gnus)Customizing Articles' and Info node
1184 `(gnus)Picons' for details."
1185 :group 'gnus-article-treat
1186 :type gnus-article-treat-head-custom)
1187 (put 'gnus-treat-from-picon 'highlight t)
1189 (defcustom gnus-treat-mail-picon
1190 (if (and (gnus-image-type-available-p 'xpm)
1191 (gnus-picons-installed-p))
1193 "Display picons in To and Cc headers.
1194 Valid values are nil, t, `head', `last', an integer or a predicate.
1195 See Info node `(gnus)Customizing Articles' and Info node
1196 `(gnus)Picons' for details."
1197 :group 'gnus-article-treat
1198 :type gnus-article-treat-head-custom)
1199 (put 'gnus-treat-mail-picon 'highlight t)
1201 (defcustom gnus-treat-newsgroups-picon
1202 (if (and (gnus-image-type-available-p 'xpm)
1203 (gnus-picons-installed-p))
1205 "Display picons in the Newsgroups and Followup-To headers.
1206 Valid values are nil, t, `head', `last', an integer or a predicate.
1207 See Info node `(gnus)Customizing Articles' and Info node
1208 `(gnus)Picons' for details."
1209 :group 'gnus-article-treat
1210 :type gnus-article-treat-head-custom)
1211 (put 'gnus-treat-newsgroups-picon 'highlight t)
1213 (defcustom gnus-treat-body-boundary
1214 (if (or gnus-treat-newsgroups-picon
1215 gnus-treat-mail-picon
1216 gnus-treat-from-picon)
1218 "Draw a boundary at the end of the headers.
1219 Valid values are nil, t, `head', `last', an integer or a predicate.
1220 See Info node `(gnus)Customizing Articles' for details."
1222 :group 'gnus-article-treat
1223 :type gnus-article-treat-custom)
1225 (defcustom gnus-treat-capitalize-sentences nil
1226 "Capitalize sentence-starting words.
1227 Valid values are nil, t, `head', `last', an integer or a predicate.
1228 See Info node `(gnus)Customizing Articles' for details."
1230 :group 'gnus-article-treat
1231 :type gnus-article-treat-custom)
1233 (defcustom gnus-treat-fill-long-lines nil
1235 Valid values are nil, t, `head', `last', an integer or a predicate.
1236 See Info node `(gnus)Customizing Articles' for details."
1237 :group 'gnus-article-treat
1238 :type gnus-article-treat-custom)
1240 (defcustom gnus-treat-play-sounds nil
1242 Valid values are nil, t, `head', `last', an integer or a predicate.
1243 See Info node `(gnus)Customizing Articles' for details."
1245 :group 'gnus-article-treat
1246 :type gnus-article-treat-custom)
1248 (defcustom gnus-treat-decode-article-as-default-mime-charset nil
1249 "Decode an article as `default-mime-charset'. For instance, if you want to
1250 attempt to decode an article even if the value of `gnus-show-mime' is nil,
1251 you could set this variable to something like: nil for don't decode, t for
1252 decode the body, '(or header t) for the whole article, etc."
1253 :group 'gnus-article-treat
1254 :type '(radio (const :tag "Off" nil)
1255 (const :tag "Decode body" t)
1256 (const :tag "Decode all" (or head t))))
1258 (defcustom gnus-treat-translate nil
1259 "Translate articles from one language to another.
1260 Valid values are nil, t, `head', `last', an integer or a predicate.
1261 See Info node `(gnus)Customizing Articles' for details."
1263 :group 'gnus-article-treat
1264 :type gnus-article-treat-custom)
1266 (defcustom gnus-treat-x-pgp-sig nil
1268 To automatically treat X-PGP-Sig, set it to head.
1269 Valid values are nil, t, `head', `last', an integer or a predicate.
1270 See Info node `(gnus)Customizing Articles' for details."
1271 :group 'gnus-article-treat
1272 :group 'mime-security
1273 :type gnus-article-treat-custom)
1275 (defvar gnus-article-encrypt-protocol-alist
1276 '(("PGP" . mml2015-self-encrypt)))
1278 ;; Set to nil if more than one protocol added to
1279 ;; gnus-article-encrypt-protocol-alist.
1280 (defcustom gnus-article-encrypt-protocol "PGP"
1281 "The protocol used for encrypt articles.
1282 It is a string, such as \"PGP\". If nil, ask user."
1284 :group 'mime-security)
1286 ;;; Internal variables
1288 (defvar gnus-english-month-names
1289 '("January" "February" "March" "April" "May" "June" "July" "August"
1290 "September" "October" "November" "December"))
1292 (defvar article-goto-body-goes-to-point-min-p nil)
1293 (defvar gnus-article-wash-types nil)
1294 (defvar gnus-article-emphasis-alist nil)
1295 (defvar gnus-article-image-alist nil)
1297 (defvar gnus-article-mime-handle-alist-1 nil)
1298 (defvar gnus-treatment-function-alist
1299 '((gnus-treat-decode-article-as-default-mime-charset
1300 gnus-article-decode-article-as-default-mime-charset)
1301 (gnus-treat-x-pgp-sig gnus-article-verify-x-pgp-sig)
1302 (gnus-treat-strip-banner gnus-article-strip-banner)
1303 (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
1304 (gnus-treat-buttonize gnus-article-add-buttons)
1305 (gnus-treat-fill-article gnus-article-fill-cited-article)
1306 (gnus-treat-fill-long-lines gnus-article-fill-long-lines)
1307 (gnus-treat-strip-cr gnus-article-remove-cr)
1308 (gnus-treat-date-ut gnus-article-date-ut)
1309 (gnus-treat-date-local gnus-article-date-local)
1310 (gnus-treat-date-english gnus-article-date-english)
1311 (gnus-treat-date-lapsed gnus-article-date-lapsed)
1312 (gnus-treat-date-original gnus-article-date-original)
1313 (gnus-treat-date-user-defined gnus-article-date-user)
1314 (gnus-treat-date-iso8601 gnus-article-date-iso8601)
1315 (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
1316 (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
1317 (gnus-treat-hide-signature gnus-article-hide-signature)
1318 (gnus-treat-hide-citation gnus-article-hide-citation)
1319 (gnus-treat-hide-citation-maybe gnus-article-hide-citation-maybe)
1320 (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
1321 (gnus-treat-leading-whitespace gnus-article-remove-leading-whitespace)
1322 (gnus-treat-strip-pgp gnus-article-hide-pgp)
1323 (gnus-treat-strip-pem gnus-article-hide-pem)
1324 (gnus-treat-from-picon gnus-treat-from-picon)
1325 (gnus-treat-mail-picon gnus-treat-mail-picon)
1326 (gnus-treat-newsgroups-picon gnus-treat-newsgroups-picon)
1327 (gnus-treat-highlight-headers gnus-article-highlight-headers)
1328 (gnus-treat-highlight-citation gnus-article-highlight-citation)
1329 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1330 (gnus-treat-strip-trailing-blank-lines
1331 gnus-article-remove-trailing-blank-lines)
1332 (gnus-treat-strip-leading-blank-lines
1333 gnus-article-strip-leading-blank-lines)
1334 (gnus-treat-strip-multiple-blank-lines
1335 gnus-article-strip-multiple-blank-lines)
1336 (gnus-treat-overstrike gnus-article-treat-overstrike)
1337 (gnus-treat-unfold-headers gnus-article-treat-unfold-headers)
1338 (gnus-treat-fold-headers gnus-article-treat-fold-headers)
1339 ;; Displaying X-Face should be done after unfolding headers
1340 ;; to protect bitmap lines.
1341 (gnus-treat-display-xface gnus-article-display-x-face)
1342 (gnus-treat-fold-newsgroups gnus-article-treat-fold-newsgroups)
1343 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
1344 (gnus-treat-display-smileys gnus-treat-smiley)
1345 (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
1346 (gnus-treat-emphasize gnus-article-emphasize)
1347 (gnus-treat-body-boundary gnus-article-treat-body-boundary)
1348 (gnus-treat-play-sounds gnus-earcon-display)))
1350 (defvar gnus-article-mime-handle-alist nil)
1351 (defvar article-lapsed-timer nil)
1352 (defvar gnus-article-current-summary nil)
1354 (defvar gnus-article-mode-syntax-table
1355 (let ((table (copy-syntax-table text-mode-syntax-table)))
1356 ;; This causes the citation match run O(2^n).
1357 ;; (modify-syntax-entry ?- "w" table)
1358 (modify-syntax-entry ?> ")" table)
1359 (modify-syntax-entry ?< "(" table)
1361 "Syntax table used in article mode buffers.
1362 Initialized from `text-mode-syntax-table.")
1364 (defvar gnus-save-article-buffer nil)
1366 (defvar gnus-article-mode-line-format-alist
1367 (nconc '((?w (gnus-article-wash-status) ?s)
1368 (?m (gnus-article-mime-part-status) ?s))
1369 gnus-summary-mode-line-format-alist))
1371 (defvar gnus-number-of-articles-to-be-saved nil)
1373 (defvar gnus-inhibit-hiding nil)
1375 ;;; Macros for dealing with the article buffer.
1377 (defmacro gnus-with-article-headers (&rest forms)
1379 (set-buffer gnus-article-buffer)
1381 (let ((buffer-read-only nil)
1382 (inhibit-point-motion-hooks t)
1383 (case-fold-search t))
1384 (article-narrow-to-head)
1387 (put 'gnus-with-article-headers 'lisp-indent-function 0)
1388 (put 'gnus-with-article-headers 'edebug-form-spec '(body))
1390 (defmacro gnus-with-article-buffer (&rest forms)
1392 (set-buffer gnus-article-buffer)
1393 (let ((buffer-read-only nil))
1396 (put 'gnus-with-article-buffer 'lisp-indent-function 0)
1397 (put 'gnus-with-article-buffer 'edebug-form-spec '(body))
1399 (defun gnus-article-goto-header (header)
1400 "Go to HEADER, which is a regular expression."
1401 (re-search-forward (concat "^\\(" header "\\):") nil t))
1403 (defsubst gnus-article-hide-text (b e props)
1404 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
1405 (gnus-add-text-properties-when 'article-type nil b e props)
1406 (when (memq 'intangible props)
1408 (max (1- b) (point-min))
1409 b 'intangible (cddr (memq 'intangible props)))))
1411 (defsubst gnus-article-unhide-text (b e)
1412 "Remove hidden text properties from region between B and E."
1413 (remove-text-properties b e gnus-hidden-properties)
1414 (when (memq 'intangible gnus-hidden-properties)
1415 (put-text-property (max (1- b) (point-min))
1416 b 'intangible nil)))
1418 (defun gnus-article-hide-text-type (b e type)
1419 "Hide text of TYPE between B and E."
1420 (gnus-add-wash-type type)
1421 (gnus-article-hide-text
1422 b e (cons 'article-type (cons type gnus-hidden-properties))))
1424 (defun gnus-article-unhide-text-type (b e type)
1425 "Unhide text of TYPE between B and E."
1426 (gnus-delete-wash-type type)
1427 (remove-text-properties
1428 b e (cons 'article-type (cons type gnus-hidden-properties)))
1429 (when (memq 'intangible gnus-hidden-properties)
1430 (put-text-property (max (1- b) (point-min))
1431 b 'intangible nil)))
1433 (defun gnus-article-hide-text-of-type (type)
1434 "Hide text of TYPE in the current buffer."
1436 (let ((b (point-min))
1438 (while (setq b (text-property-any b e 'article-type type))
1439 (add-text-properties b (incf b) gnus-hidden-properties)))))
1441 (defun gnus-article-delete-text-of-type (type)
1442 "Delete text of TYPE in the current buffer."
1444 (let ((b (point-min)))
1445 (while (setq b (text-property-any b (point-max) 'article-type type))
1447 b (or (text-property-not-all b (point-max) 'article-type type)
1450 (defun gnus-article-delete-invisible-text ()
1451 "Delete all invisible text in the current buffer."
1453 (let ((b (point-min)))
1454 (while (setq b (text-property-any b (point-max) 'invisible t))
1456 b (or (text-property-not-all b (point-max) 'invisible t)
1459 (defun gnus-article-text-type-exists-p (type)
1460 "Say whether any text of type TYPE exists in the buffer."
1461 (text-property-any (point-min) (point-max) 'article-type type))
1463 (defsubst gnus-article-header-rank ()
1464 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1465 (let ((list gnus-sorted-header-list)
1468 (when (looking-at (car list))
1470 (setq list (cdr list))
1474 (defun article-hide-headers (&optional arg delete)
1475 "Hide unwanted headers and possibly sort them as well."
1476 (interactive (gnus-article-hidden-arg))
1477 ;; Lars said that this function might be inhibited.
1478 (if (gnus-article-check-hidden-text 'headers arg)
1480 ;; Show boring headers as well.
1481 (gnus-article-show-hidden-text 'boring-headers)
1482 (when (eq 1 (point-min))
1483 (set-window-start (get-buffer-window (current-buffer)) 1)))
1484 (unless gnus-inhibit-hiding
1487 (let ((inhibit-read-only t)
1488 (case-fold-search t)
1489 (max (1+ (length gnus-sorted-header-list)))
1490 (ignored (when (not gnus-visible-headers)
1491 (cond ((stringp gnus-ignored-headers)
1492 gnus-ignored-headers)
1493 ((listp gnus-ignored-headers)
1494 (mapconcat 'identity gnus-ignored-headers
1497 (cond ((stringp gnus-visible-headers)
1498 gnus-visible-headers)
1499 ((and gnus-visible-headers
1500 (listp gnus-visible-headers))
1501 (mapconcat 'identity gnus-visible-headers "\\|"))))
1502 (inhibit-point-motion-hooks t)
1504 ;; First we narrow to just the headers.
1505 (article-narrow-to-head)
1506 ;; Hide any "From " lines at the beginning of (mail) articles.
1507 (while (looking-at "From ")
1511 (delete-region (point-min) (point))
1512 (gnus-article-hide-text (point-min) (point)
1513 (nconc (list 'article-type 'headers)
1514 gnus-hidden-properties))))
1515 ;; Then treat the rest of the header lines.
1516 ;; Then we use the two regular expressions
1517 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1518 ;; select which header lines is to remain visible in the
1520 (while (re-search-forward "^[^ \t:]*:" nil t)
1522 ;; Mark the rank of the header.
1524 (point) (1+ (point)) 'message-rank
1525 (if (or (and visible (looking-at visible))
1527 (not (looking-at ignored))))
1528 (gnus-article-header-rank)
1531 (message-sort-headers-1)
1532 (when (setq beg (text-property-any
1533 (point-min) (point-max) 'message-rank (+ 2 max)))
1534 ;; We delete or make invisible the unwanted headers.
1535 (gnus-add-wash-type 'headers)
1538 (add-text-properties
1539 (point-min) (+ 5 (point-min))
1540 '(article-type headers dummy-invisible t))
1541 (delete-region beg (point-max)))
1542 (gnus-article-hide-text-type beg (point-max) 'headers)))))))))
1544 (defun article-hide-boring-headers (&optional arg)
1545 "Toggle hiding of headers that aren't very interesting.
1546 If given a negative prefix, always show; if given a positive prefix,
1548 (interactive (gnus-article-hidden-arg))
1549 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1550 (not gnus-show-all-headers))
1553 (let ((buffer-read-only nil)
1554 (list gnus-boring-article-headers)
1555 (inhibit-point-motion-hooks t)
1557 (article-narrow-to-head)
1559 (setq elem (pop list))
1560 (goto-char (point-min))
1562 ;; Hide empty headers.
1564 (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1566 (gnus-article-hide-text-type
1567 (progn (beginning-of-line) (point))
1570 (if (re-search-forward "^[^ \t]" nil t)
1574 ;; Hide boring Newsgroups header.
1575 ((eq elem 'newsgroups)
1576 (when (gnus-string-equal
1577 (gnus-fetch-field "newsgroups")
1578 (gnus-group-real-name
1579 (if (boundp 'gnus-newsgroup-name)
1582 (gnus-article-hide-header "newsgroups")))
1583 ((eq elem 'to-address)
1584 (let ((to (message-fetch-field "to"))
1586 (gnus-parameter-to-address
1587 (if (boundp 'gnus-newsgroup-name)
1588 gnus-newsgroup-name ""))))
1589 (when (and to to-address
1592 ;; only one address in To
1593 (nth 1 (mail-extract-address-components to))
1595 (gnus-article-hide-header "to"))))
1596 ((eq elem 'followup-to)
1597 (when (gnus-string-equal
1598 (message-fetch-field "followup-to")
1599 (message-fetch-field "newsgroups"))
1600 (gnus-article-hide-header "followup-to")))
1601 ((eq elem 'reply-to)
1602 (let ((from (message-fetch-field "from"))
1603 (reply-to (message-fetch-field "reply-to")))
1608 (nth 1 (mail-extract-address-components from))
1609 (nth 1 (mail-extract-address-components reply-to)))))
1610 (gnus-article-hide-header "reply-to"))))
1612 (let ((date (message-fetch-field "date")))
1614 (< (days-between (current-time-string) date)
1616 (gnus-article-hide-header "date"))))
1618 (let ((to (message-fetch-field "to"))
1619 (cc (message-fetch-field "cc")))
1620 (when (> (length to) 1024)
1621 (gnus-article-hide-header "to"))
1622 (when (> (length cc) 1024)
1623 (gnus-article-hide-header "cc"))))
1627 (goto-char (point-min))
1628 (while (re-search-forward "^to:" nil t)
1629 (setq to-count (1+ to-count)))
1630 (when (> to-count 1)
1631 (while (> to-count 0)
1632 (goto-char (point-min))
1634 (re-search-forward "^to:" nil nil to-count)
1636 (narrow-to-region (point) (point-max))
1637 (gnus-article-hide-header "to"))
1638 (setq to-count (1- to-count))))
1639 (goto-char (point-min))
1640 (while (re-search-forward "^cc:" nil t)
1641 (setq cc-count (1+ cc-count)))
1642 (when (> cc-count 1)
1643 (while (> cc-count 0)
1644 (goto-char (point-min))
1646 (re-search-forward "^cc:" nil nil cc-count)
1648 (narrow-to-region (point) (point-max))
1649 (gnus-article-hide-header "cc"))
1650 (setq cc-count (1- cc-count)))))))))))))
1652 (defun gnus-article-hide-header (header)
1654 (goto-char (point-min))
1655 (when (re-search-forward (concat "^" header ":") nil t)
1656 (gnus-article-hide-text-type
1657 (progn (beginning-of-line) (point))
1660 (if (re-search-forward "^[^ \t]" nil t)
1665 (defun article-toggle-headers (&optional arg)
1666 "Toggle hiding of headers. If given a negative prefix, always show;
1667 if given a positive prefix, always hide."
1668 (interactive (gnus-article-hidden-arg))
1669 (let ((force (when (numberp arg)
1670 (cond ((> arg 0) 'always-hide)
1671 ((< arg 0) 'always-show))))
1672 (window (get-buffer-window gnus-article-buffer))
1673 (header-end (point-min))
1674 header-start field-end field-start
1675 (inhibit-point-motion-hooks t)
1676 (inhibit-read-only t))
1679 (while (and (setq header-start
1680 (text-property-any header-end (point-max)
1681 'article-treated-header t))
1683 (text-property-not-all header-start (point-max)
1684 'article-treated-header t)))
1685 (setq field-end header-start)
1687 (;; Hide exposed invisible fields.
1688 (and (not (eq 'always-show force))
1690 (text-property-any field-end header-end
1691 'exposed-invisible-field t)))
1692 (while (and field-start
1693 (setq field-end (text-property-not-all
1694 field-start header-end
1695 'exposed-invisible-field t)))
1696 (add-text-properties field-start field-end gnus-hidden-properties)
1697 (setq field-start (text-property-any field-end header-end
1698 'exposed-invisible-field t)))
1699 (put-text-property header-start header-end
1700 'exposed-invisible-field nil))
1701 (;; Expose invisible fields.
1702 (and (not (eq 'always-hide force))
1704 (text-property-any field-end header-end 'invisible t)))
1705 (while (and field-start
1706 (setq field-end (text-property-not-all
1707 field-start header-end
1709 ;; If the invisible text is not terminated with newline, we
1710 ;; won't expose it. Because it may be created by x-face-mule.
1711 ;; BTW, XEmacs sometimes fail in putting an invisible text
1712 ;; property with `gnus-article-hide-text' (really?). In that
1713 ;; case, the invisible text might be started from the middle of
1714 ;; a line, so we will expose the sort of thing.
1715 (when (or (not (or (eq header-start field-start)
1716 (eq ?\n (char-before field-start))))
1717 (eq ?\n (char-before field-end))
1718 ;; Expose a boundary line anyway.
1721 (buffer-substring (max (- field-end 13) header-start)
1723 (remove-text-properties field-start field-end
1724 gnus-hidden-properties)
1725 (put-text-property field-start field-end
1726 'exposed-invisible-field t))
1727 (setq field-start (text-property-any field-end header-end
1730 (not (eq 'always-show force))
1731 (narrow-to-region header-start header-end)
1732 (article-hide-headers)
1733 ;; Re-display X-Face image under XEmacs.
1734 (when (and (featurep 'xemacs)
1735 (gnus-functionp gnus-article-x-face-command))
1736 (let ((func (cadr (assq 'gnus-treat-display-xface
1737 gnus-treatment-function-alist)))
1739 (when (and (not gnus-inhibit-treatment)
1741 (gnus-treat-predicate gnus-treat-display-xface))
1743 (put-text-property header-start header-end 'read-only nil))))
1746 (goto-char (point-min))
1748 (set-window-start window (point-min))))))
1750 (defvar gnus-article-normalized-header-length 40
1751 "Length of normalized headers.")
1753 (defun article-normalize-headers ()
1754 "Make all header lines 40 characters long."
1756 (let ((buffer-read-only nil)
1760 (article-narrow-to-head)
1763 ((< (setq column (- (gnus-point-at-eol) (point)))
1764 gnus-article-normalized-header-length)
1766 (insert (make-string
1767 (- gnus-article-normalized-header-length column)
1769 ((> column gnus-article-normalized-header-length)
1770 (gnus-put-text-property
1772 (forward-char gnus-article-normalized-header-length)
1779 (forward-line 1))))))
1781 (defun article-treat-dumbquotes ()
1782 "Translate M****s*** sm*rtq**t*s into proper text.
1783 Note that this function guesses whether a character is a sm*rtq**t* or
1784 not, so it should only be used interactively.
1786 Sm*rtq**t*s are M****s***'s unilateral extension to the character map
1787 in an attempt to provide more quoting characters. If you see
1788 something like \\222 or \\264 where you're expecting some kind of
1789 apostrophe or quotation mark, then try this wash."
1791 (article-translate-strings gnus-article-dumbquotes-map))
1793 (defun article-translate-characters (from to)
1794 "Translate all characters in the body of the article according to FROM and TO.
1795 FROM is a string of characters to translate from; to is a string of
1796 characters to translate to."
1798 (when (article-goto-body)
1799 (let ((buffer-read-only nil)
1800 (x (make-string 225 ?x))
1802 (while (< (incf i) (length x))
1805 (while (< i (length from))
1806 (aset x (aref from i) (aref to i))
1808 (translate-region (point) (point-max) x)))))
1810 (defun article-translate-strings (map)
1811 "Translate all string in the body of the article according to MAP.
1812 MAP is an alist where the elements are on the form (\"from\" \"to\")."
1814 (when (article-goto-body)
1815 (let ((buffer-read-only nil)
1817 (while (setq elem (pop map))
1819 (while (search-forward (car elem) nil t)
1820 (replace-match (cadr elem)))))))))
1822 (defun article-treat-overstrike ()
1823 "Translate overstrikes into bold text."
1826 (when (article-goto-body)
1827 (let ((buffer-read-only nil))
1828 (while (search-forward "\b" nil t)
1829 (let ((next (char-after))
1833 previous (char-after))
1837 ;; We do the boldification/underlining by hiding the
1838 ;; overstrikes and putting the proper text property
1842 (gnus-article-hide-text-type start (point) 'overstrike)
1843 (put-text-property (point) end 'face 'bold))
1845 (gnus-article-hide-text-type
1846 (1- (point)) (1+ (point)) 'overstrike)
1848 start (1- (point)) 'face 'underline))
1850 (gnus-article-hide-text-type start (point) 'overstrike)
1852 (point) end 'face 'underline)))))))))
1854 (defun gnus-article-treat-unfold-headers ()
1855 "Unfold folded message headers.
1856 Only the headers that fit into the current window width will be
1859 (gnus-with-article-headers
1863 (mail-header-narrow-to-field)
1864 (let ((header (buffer-substring (point-min) (point-max))))
1867 (goto-char (point-min))
1868 (while (re-search-forward "[\t ]*\n[\t ]+" nil t)
1869 (replace-match " " t t)))
1870 (setq length (- (point-max) (point-min) 1)))
1871 (when (< length (window-width))
1872 (while (re-search-forward "[\t ]*\n[\t ]+" nil t)
1873 (replace-match " " t t)))
1874 (goto-char (point-max)))))))
1876 (defun gnus-article-treat-fold-headers ()
1877 "Fold message headers."
1879 (gnus-with-article-headers
1882 (mail-header-narrow-to-field)
1883 (mail-header-fold-field)
1884 (goto-char (point-max))))))
1886 (defun gnus-treat-smiley ()
1887 "Display textual emoticons (\"smileys\") as small graphical icons."
1889 (unless (featurep 'xemacs)
1890 (when (and (>= emacs-major-version 21)
1891 (not gnus-article-should-use-smiley-mule)
1892 gnus-article-smiley-mule-loaded-p)
1893 (load "smiley-ems" nil t)
1894 (setq gnus-article-smiley-mule-loaded-p nil))
1895 (when (and gnus-article-should-use-smiley-mule
1896 (not gnus-article-smiley-mule-loaded-p))
1897 (load "smiley-mule" nil t)
1898 (setq gnus-article-smiley-mule-loaded-p t)))
1899 (gnus-with-article-buffer
1900 (if (memq 'smiley gnus-article-wash-types)
1901 (gnus-delete-images 'smiley)
1903 (let ((images (smiley-region (point) (point-max))))
1905 (gnus-add-wash-type 'smiley)
1906 (dolist (image images)
1907 (gnus-add-image 'smiley image)))))))
1909 (defun gnus-article-remove-images ()
1910 "Remove all images from the article buffer."
1912 (gnus-with-article-buffer
1913 (dolist (elem gnus-article-image-alist)
1914 (gnus-delete-images (car elem)))))
1916 (defun gnus-article-treat-fold-newsgroups ()
1917 "Unfold folded message headers.
1918 Only the headers that fit into the current window width will be
1921 (gnus-with-article-headers
1922 (while (gnus-article-goto-header "newsgroups\\|followup-to")
1924 (mail-header-narrow-to-field)
1925 (while (re-search-forward ", *" nil t)
1926 (replace-match ", " t t))
1927 (mail-header-fold-field)
1928 (goto-char (point-max))))))
1930 (defun gnus-article-treat-body-boundary ()
1931 "Place a boundary line at the end of the headers."
1933 (when (and gnus-body-boundary-delimiter
1934 (> (length gnus-body-boundary-delimiter) 0))
1935 (gnus-with-article-headers
1936 (goto-char (point-max))
1937 (let ((start (point)))
1938 (insert "X-Boundary: ")
1939 (gnus-add-text-properties start (point) '(invisible t intangible t))
1941 (while (>= (1- (window-width)) (length str))
1942 (setq str (concat str gnus-body-boundary-delimiter)))
1943 (substring str 0 (1- (window-width))))
1946 (defun article-fill-long-lines ()
1947 "Fill lines that are wider than the window width."
1950 (let ((buffer-read-only nil)
1951 (width (window-width (get-buffer-window (current-buffer)))))
1954 (let ((adaptive-fill-mode nil)) ;Why? -sm
1957 (when (>= (current-column) (min fill-column width))
1958 (narrow-to-region (point) (gnus-point-at-bol))
1959 (fill-paragraph nil)
1960 (goto-char (point-max))
1962 (forward-line 1)))))))
1964 (defun article-capitalize-sentences ()
1965 "Capitalize the first word in each sentence."
1968 (let ((buffer-read-only nil)
1969 (paragraph-start "^[\n\^L]"))
1973 (forward-sentence)))))
1975 (defun article-remove-cr ()
1976 "Remove trailing CRs and then translate remaining CRs into LFs."
1979 (let ((buffer-read-only nil))
1980 (goto-char (point-min))
1981 (while (re-search-forward "\r+$" nil t)
1982 (replace-match "" t t))
1983 (goto-char (point-min))
1984 (while (search-forward "\r" nil t)
1985 (replace-match "\n" t t)))))
1987 (defun article-remove-trailing-blank-lines ()
1988 "Remove all trailing blank lines from the article."
1991 (let ((buffer-read-only nil))
1992 (goto-char (point-max))
1996 (while (and (not (bobp))
1997 (looking-at "^[ \t]*$")
1998 (not (gnus-annotation-in-region-p
1999 (point) (gnus-point-at-eol))))
2004 (defun article-display-x-face (&optional force)
2005 "Look for an X-Face header and display it if present."
2006 (interactive (list 'force))
2007 (let ((wash-face-p buffer-read-only)) ;; When type `W f'
2008 (gnus-with-article-headers
2009 ;; Delete the old process, if any.
2010 (when (process-status "article-x-face")
2011 (delete-process "article-x-face"))
2012 (if (memq 'xface gnus-article-wash-types)
2013 ;; We have already displayed X-Faces, so we remove them
2015 (gnus-delete-images 'xface)
2017 (let (x-faces from face grey)
2019 (when (and wash-face-p
2021 (goto-char (point-min))
2022 (not (re-search-forward
2023 "^X-Face\\(-[0-9]+\\)?:[\t ]*" nil t)))
2024 (gnus-buffer-live-p gnus-original-article-buffer))
2025 ;; If type `W f', use gnus-original-article-buffer,
2026 ;; otherwise use the current buffer because displaying
2027 ;; RFC822 parts calls this function too.
2028 (set-buffer gnus-original-article-buffer))
2030 (mail-narrow-to-head)
2031 (while (gnus-article-goto-header "x-face\\(-[0-9]+\\)?")
2032 (when (match-beginning 2)
2034 (push (mail-header-field-value) x-faces))
2035 (setq from (message-fetch-field "from"))))
2037 (let ((xpm (gnus-convert-gray-x-face-to-xpm x-faces))
2040 (setq image (gnus-create-image xpm 'xpm t))
2041 (gnus-article-goto-header "from")
2043 (insert "From: [no `from' set]\n")
2045 (gnus-add-wash-type 'xface)
2046 (gnus-add-image 'xface image)
2047 (gnus-put-image image)))
2048 ;; Sending multiple EOFs to xv doesn't work, so we only do a
2049 ;; single external face.
2050 (when (stringp gnus-article-x-face-command)
2051 (setq x-faces (list (car x-faces))))
2052 (while (and (setq face (pop x-faces))
2053 gnus-article-x-face-command
2055 ;; Check whether this face is censored.
2056 (not gnus-article-x-face-too-ugly)
2057 (and gnus-article-x-face-too-ugly from
2058 (not (string-match gnus-article-x-face-too-ugly
2060 ;; We display the face.
2061 (if (symbolp gnus-article-x-face-command)
2062 ;; The command is a lisp function, so we call it.
2063 (if (gnus-functionp gnus-article-x-face-command)
2064 (funcall gnus-article-x-face-command face)
2065 (error "%s is not a function" gnus-article-x-face-command))
2066 ;; The command is a string, so we interpret the command
2067 ;; as a, well, command, and fork it off.
2068 (let ((process-connection-type nil))
2069 (process-kill-without-query
2071 "article-x-face" nil shell-file-name shell-command-switch
2072 gnus-article-x-face-command))
2075 (process-send-region "article-x-face"
2076 (point-min) (point-max)))
2077 (process-send-eof "article-x-face"))))))))))
2079 (defun article-decode-mime-words ()
2080 "Decode all MIME-encoded words in the article."
2083 (set-buffer gnus-article-buffer)
2084 (let ((inhibit-point-motion-hooks t)
2086 (mail-parse-charset gnus-newsgroup-charset)
2087 (mail-parse-ignored-charsets
2088 (save-excursion (set-buffer gnus-summary-buffer)
2089 gnus-newsgroup-ignored-charsets)))
2090 (mail-decode-encoded-word-region (point-min) (point-max)))))
2092 (defun article-decode-charset (&optional prompt)
2093 "Decode charset-encoded text in the article.
2094 If PROMPT (the prefix), prompt for a coding system to use."
2096 (let ((inhibit-point-motion-hooks t) (case-fold-search t)
2098 (mail-parse-charset gnus-newsgroup-charset)
2099 (mail-parse-ignored-charsets
2100 (save-excursion (condition-case nil
2101 (set-buffer gnus-summary-buffer)
2103 gnus-newsgroup-ignored-charsets))
2104 ct cte ctl charset format)
2107 (article-narrow-to-head)
2108 (setq ct (message-fetch-field "Content-Type" t)
2109 cte (message-fetch-field "Content-Transfer-Encoding" t)
2110 ctl (and ct (ignore-errors
2111 (mail-header-parse-content-type ct)))
2114 (mm-read-coding-system "Charset to decode: "))
2116 (mail-content-type-get ctl 'charset)))
2117 format (and ctl (mail-content-type-get ctl 'format)))
2119 (setq cte (mail-header-strip cte)))
2120 (if (and ctl (not (string-match "/" (car ctl))))
2122 (goto-char (point-max)))
2125 (narrow-to-region (point) (point-max))
2126 (when (and (eq mail-parse-charset 'gnus-decoded)
2127 (eq (mm-body-7-or-8) '8bit))
2128 ;; The text code could have been decoded.
2129 (setq charset mail-parse-charset))
2130 (when (and (or (not ctl)
2131 (equal (car ctl) "text/plain"))
2132 (not format)) ;; article with format will decode later.
2134 charset (and cte (intern (downcase
2135 (gnus-strip-whitespace cte))))
2138 (defun article-decode-encoded-words ()
2139 "Remove encoded-word encoding from headers."
2140 (let (buffer-read-only)
2141 (let ((charset (save-excursion
2142 (set-buffer gnus-summary-buffer)
2143 default-mime-charset)))
2144 (mime-decode-header-in-buffer charset))))
2146 (defun article-decode-group-name ()
2147 "Decode group names in `Newsgroups:'."
2148 (let ((inhibit-point-motion-hooks t)
2150 (method (gnus-find-method-for-group gnus-newsgroup-name)))
2151 (when (and (or gnus-group-name-charset-method-alist
2152 gnus-group-name-charset-group-alist)
2153 (gnus-buffer-live-p gnus-original-article-buffer))
2154 (when (nnmail-fetch-field "Newsgroups")
2155 (nnheader-replace-header "Newsgroups"
2156 (gnus-decode-newsgroups
2157 (with-current-buffer
2158 gnus-original-article-buffer
2159 (nnmail-fetch-field "Newsgroups"))
2160 gnus-newsgroup-name method)))
2161 (when (nnmail-fetch-field "Followup-To")
2162 (nnheader-replace-header "Followup-To"
2163 (gnus-decode-newsgroups
2164 (with-current-buffer
2165 gnus-original-article-buffer
2166 (nnmail-fetch-field "Followup-To"))
2167 gnus-newsgroup-name method))))))
2169 (defun article-de-quoted-unreadable (&optional force read-charset)
2170 "Translate a quoted-printable-encoded article.
2171 If FORCE, decode the article whether it is marked as quoted-printable
2173 If READ-CHARSET, ask for a coding system."
2174 (interactive (list 'force current-prefix-arg))
2176 (let ((buffer-read-only nil) type charset)
2177 (if (gnus-buffer-live-p gnus-original-article-buffer)
2178 (with-current-buffer gnus-original-article-buffer
2180 (gnus-fetch-field "content-transfer-encoding"))
2181 (let* ((ct (gnus-fetch-field "content-type"))
2184 (mail-header-parse-content-type ct)))))
2185 (setq charset (and ctl
2186 (mail-content-type-get ctl 'charset)))
2187 (if (stringp charset)
2188 (setq charset (intern (downcase charset)))))))
2190 (setq charset (mm-read-coding-system "Charset: " charset)))
2192 (setq charset gnus-newsgroup-charset))
2194 (and type (let ((case-fold-search t))
2195 (string-match "quoted-printable" type))))
2197 (quoted-printable-decode-region
2198 (point) (point-max) (mm-charset-to-coding-system charset))))))
2200 (defun article-de-base64-unreadable (&optional force read-charset)
2201 "Translate a base64 article.
2202 If FORCE, decode the article whether it is marked as base64 not.
2203 If READ-CHARSET, ask for a coding system."
2204 (interactive (list 'force current-prefix-arg))
2206 (let ((buffer-read-only nil) type charset)
2207 (if (gnus-buffer-live-p gnus-original-article-buffer)
2208 (with-current-buffer gnus-original-article-buffer
2210 (gnus-fetch-field "content-transfer-encoding"))
2211 (let* ((ct (gnus-fetch-field "content-type"))
2214 (mail-header-parse-content-type ct)))))
2215 (setq charset (and ctl
2216 (mail-content-type-get ctl 'charset)))
2217 (if (stringp charset)
2218 (setq charset (intern (downcase charset)))))))
2220 (setq charset (mm-read-coding-system "Charset: " charset)))
2222 (setq charset gnus-newsgroup-charset))
2224 (and type (let ((case-fold-search t))
2225 (string-match "base64" type))))
2228 (narrow-to-region (point) (point-max))
2229 (base64-decode-region (point-min) (point-max))
2230 (mm-decode-coding-region
2231 (point-min) (point-max) (mm-charset-to-coding-system charset)))))))
2236 (defun article-decode-HZ ()
2237 "Translate a HZ-encoded article."
2241 (let ((buffer-read-only nil))
2242 (rfc1843-decode-region (point-min) (point-max)))))
2244 (defun article-wash-html (&optional read-charset)
2245 "Format an html article.
2246 If READ-CHARSET, ask for a coding system."
2249 (let ((buffer-read-only nil)
2251 (if (gnus-buffer-live-p gnus-original-article-buffer)
2252 (with-current-buffer gnus-original-article-buffer
2253 (let* ((ct (gnus-fetch-field "content-type"))
2256 (mail-header-parse-content-type ct)))))
2257 (setq charset (and ctl
2258 (mail-content-type-get ctl 'charset)))
2259 (if (stringp charset)
2260 (setq charset (intern (downcase charset)))))))
2262 (setq charset (mm-read-coding-system "Charset: " charset)))
2264 (setq charset gnus-newsgroup-charset))
2266 (save-window-excursion
2268 (narrow-to-region (point) (point-max))
2270 (let ((w3-strict-width (window-width))
2271 (url-standalone-mode t)
2272 (w3-honor-stylesheets nil)
2273 (w3-delay-image-loads t))
2275 (w3-region (point-min) (point-max))
2278 (defun article-hide-list-identifiers ()
2279 "Remove list identifies from the Subject header.
2280 The `gnus-list-identifiers' variable specifies what to do."
2282 (let ((inhibit-point-motion-hooks t)
2283 (regexp (if (consp gnus-list-identifiers)
2284 (mapconcat 'identity gnus-list-identifiers " *\\|")
2285 gnus-list-identifiers))
2290 (article-narrow-to-head)
2291 (goto-char (point-min))
2292 (while (re-search-forward
2293 (concat "^Subject: +\\(R[Ee]: +\\)*\\(" regexp " *\\)")
2295 (delete-region (match-beginning 2) (match-end 0))
2296 (beginning-of-line))
2297 (when (re-search-forward
2298 "^Subject: +\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" nil t)
2299 (delete-region (match-beginning 1) (match-end 1))))))))
2301 (defun article-hide-pgp ()
2302 "Remove any PGP headers and signatures in the current article."
2306 (let ((inhibit-point-motion-hooks t)
2307 buffer-read-only beg end)
2309 ;; Hide the "header".
2310 (when (re-search-forward "^-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
2311 (gnus-add-wash-type 'pgp)
2312 (delete-region (match-beginning 0) (match-end 0))
2313 ;; Remove armor headers (rfc2440 6.2)
2314 (delete-region (point) (or (re-search-forward "^[ \t]*\n" nil t)
2317 ;; Hide the actual signature.
2318 (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
2319 (setq end (1+ (match-beginning 0)))
2322 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
2324 ;; Perhaps we shouldn't hide to the end of the buffer
2325 ;; if there is no end to the signature?
2327 ;; Hide "- " PGP quotation markers.
2329 (narrow-to-region beg end)
2330 (goto-char (point-min))
2331 (while (re-search-forward "^- " nil t)
2333 (match-beginning 0) (match-end 0)))
2335 (gnus-run-hooks 'gnus-article-hide-pgp-hook))))))
2337 (defun article-hide-pem (&optional arg)
2338 "Toggle hiding of any PEM headers and signatures in the current article.
2339 If given a negative prefix, always show; if given a positive prefix,
2341 (interactive (gnus-article-hidden-arg))
2342 (unless (gnus-article-check-hidden-text 'pem arg)
2344 (let (buffer-read-only end)
2345 (goto-char (point-min))
2346 ;; Hide the horrendously ugly "header".
2347 (when (and (search-forward
2348 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
2350 (setq end (1+ (match-beginning 0))))
2351 (gnus-add-wash-type 'pem)
2352 (gnus-article-hide-text-type
2354 (if (search-forward "\n\n" nil t)
2358 ;; Hide the trailer as well
2359 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
2361 (gnus-article-hide-text-type
2362 (match-beginning 0) (match-end 0) 'pem)))))))
2364 (defun article-strip-banner ()
2365 "Strip the banner specified by the `banner' group parameter."
2369 (let ((inhibit-point-motion-hooks t)
2370 (banner (gnus-parameter-banner gnus-newsgroup-name))
2371 (gnus-signature-limit nil)
2372 buffer-read-only beg end)
2376 ((eq banner 'signature)
2377 (when (gnus-article-narrow-to-signature)
2380 (delete-region (point) (point-max))))
2382 (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
2383 (while (re-search-forward banner nil t)
2384 (delete-region (match-beginning 0) (match-end 0)))))
2386 (while (re-search-forward banner nil t)
2387 (delete-region (match-beginning 0) (match-end 0))))))))))
2389 (defun article-babel ()
2390 "Translate article using an online translation service."
2394 (set-buffer gnus-article-buffer)
2395 (when (article-goto-body)
2396 (let* ((buffer-read-only nil)
2399 (orig (buffer-substring start end))
2400 (trans (babel-as-string orig)))
2402 (narrow-to-region start end)
2403 (delete-region start end)
2406 (defun article-hide-signature (&optional arg)
2407 "Hide the signature in the current article.
2408 If given a negative prefix, always show; if given a positive prefix,
2410 (interactive (gnus-article-hidden-arg))
2416 (article-goto-body))
2417 (goto-char (point-min)))
2418 (unless (gnus-article-check-hidden-text 'signature arg)
2419 (let ((buffer-read-only nil)
2421 (while (setq button (text-property-any button (point-max)
2423 'gnus-signature-toggle))
2424 (setq button (text-property-not-all button (point-max)
2426 'gnus-signature-toggle))
2427 (when (and button (not (eobp)))
2428 (gnus-article-hide-text-type
2430 (next-single-property-change (1+ button) 'mime-view-entity
2433 (gnus-set-mode-line 'article))
2435 (defun article-strip-headers-in-body ()
2436 "Strip offensive headers from bodies."
2440 (let ((case-fold-search t))
2441 (when (looking-at "x-no-archive:")
2442 (gnus-delete-line)))))
2444 (defun article-strip-leading-blank-lines ()
2445 "Remove all blank lines from the beginning of the article."
2448 (let ((inhibit-point-motion-hooks t)
2450 (when (article-goto-body)
2451 (while (and (not (eobp))
2452 (looking-at "[ \t]*$"))
2453 (gnus-delete-line))))))
2455 (defun article-narrow-to-head ()
2456 "Narrow the buffer to the head of the message.
2457 Point is left at the beginning of the narrowed-to region."
2459 (goto-char (point-min))
2460 (if (search-forward "\n\n" nil 1)
2463 (goto-char (point-min)))
2465 (defun article-goto-body ()
2466 "Place point at the start of the body."
2467 (goto-char (point-min))
2469 ;; This variable is only bound when dealing with separate
2471 (article-goto-body-goes-to-point-min-p
2473 ((search-forward "\n\n" nil t)
2476 (goto-char (point-max))
2479 (defun article-strip-multiple-blank-lines ()
2480 "Replace consecutive blank lines with one empty line."
2483 (let ((inhibit-point-motion-hooks t)
2485 ;; First make all blank lines empty.
2487 (while (re-search-forward "^[ \t]+$" nil t)
2488 (unless (gnus-annotation-in-region-p
2489 (match-beginning 0) (match-end 0))
2490 (replace-match "" nil t)))
2491 ;; Then replace multiple empty lines with a single empty line.
2493 (while (re-search-forward "\n\n\\(\n+\\)" nil t)
2494 (unless (gnus-annotation-in-region-p
2495 (match-beginning 0) (match-end 0))
2496 (delete-region (match-beginning 1) (match-end 1)))))))
2498 (defun article-strip-leading-space ()
2499 "Remove all white space from the beginning of the lines in the article."
2502 (let ((inhibit-point-motion-hooks t)
2505 (while (re-search-forward "^[ \t]+" nil t)
2506 (replace-match "" t t)))))
2508 (defun article-strip-trailing-space ()
2509 "Remove all white space from the end of the lines in the article."
2512 (let ((inhibit-point-motion-hooks t)
2515 (while (re-search-forward "[ \t]+$" nil t)
2516 (replace-match "" t t)))))
2518 (defun article-strip-blank-lines ()
2519 "Strip leading, trailing and multiple blank lines."
2521 (article-strip-leading-blank-lines)
2522 (article-remove-trailing-blank-lines)
2523 (article-strip-multiple-blank-lines))
2525 (defun article-strip-all-blank-lines ()
2526 "Strip all blank lines."
2529 (let ((inhibit-point-motion-hooks t)
2532 (while (re-search-forward "^[ \t]*\n" nil t)
2533 (replace-match "" t t)))))
2535 (defun gnus-article-narrow-to-signature ()
2536 "Narrow to the signature; return t if a signature is found, else nil."
2537 (let ((inhibit-point-motion-hooks t))
2538 (when (gnus-article-search-signature)
2540 ;; Check whether we have some limits to what we consider
2541 ;; to be a signature.
2542 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
2543 (list gnus-signature-limit)))
2545 (while (setq limit (pop limits))
2546 (if (or (and (integerp limit)
2547 (< (- (point-max) (point)) limit))
2549 (< (count-lines (point) (point-max)) limit))
2550 (and (gnus-functionp limit)
2552 (and (stringp limit)
2553 (not (re-search-forward limit nil t))))
2554 () ; This limit did not succeed.
2558 (narrow-to-region (point) (point-max))
2561 (defun gnus-article-search-signature ()
2562 "Search the current buffer for the signature separator.
2563 Put point at the beginning of the signature separator."
2564 (let ((cur (point)))
2565 (goto-char (point-max))
2566 (if (if (stringp gnus-signature-separator)
2567 (re-search-backward gnus-signature-separator nil t)
2568 (let ((seps gnus-signature-separator))
2570 (not (re-search-backward (car seps) nil t)))
2577 (defun gnus-article-hidden-arg ()
2578 "Return the current prefix arg as a number, or 0 if no prefix."
2579 (list (if current-prefix-arg
2580 (prefix-numeric-value current-prefix-arg)
2583 (defun gnus-article-check-hidden-text (type arg)
2584 "Return nil if hiding is necessary.
2585 Arg can be nil or a number. nil and positive means hide, negative
2586 means show, 0 means toggle."
2589 (let ((hide (gnus-article-hidden-text-p type)))
2595 (gnus-article-show-hidden-text type)
2598 (if (eq hide 'hidden)
2600 (gnus-article-show-hidden-text type)
2604 (defun gnus-article-hidden-text-p (type)
2605 "Say whether the current buffer contains hidden text of type TYPE."
2606 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
2608 (not (get-text-property pos 'invisible))
2609 (not (get-text-property pos 'dummy-invisible)))
2611 (text-property-any (1+ pos) (point-max) 'article-type type)))
2616 (defun gnus-article-show-hidden-text (type &optional dummy)
2617 "Show all hidden text of type TYPE.
2618 Originally it is hide instead of DUMMY."
2619 (let ((buffer-read-only nil)
2620 (inhibit-point-motion-hooks t))
2621 (gnus-remove-text-properties-when
2623 (point-min) (point-max)
2624 (cons 'article-type (cons type
2625 gnus-hidden-properties)))
2626 (gnus-delete-wash-type type)))
2628 (defconst article-time-units
2629 `((year . ,(* 365.25 24 60 60))
2630 (week . ,(* 7 24 60 60))
2631 (day . ,(* 24 60 60))
2635 "Mapping from time units to seconds.")
2637 (defun article-date-ut (&optional type highlight header)
2638 "Convert DATE date to universal time in the current article.
2639 If TYPE is `local', convert to local time; if it is `lapsed', output
2640 how much time has lapsed since DATE. For `lapsed', the value of
2641 `gnus-article-date-lapsed-new-header' says whether the \"X-Sent:\" header
2642 should replace the \"Date:\" one, or should be added below it."
2643 (interactive (list 'ut t))
2644 (let* ((header (or header
2645 (and (eq 1 (point-min))
2646 (mail-header-date (save-excursion
2647 (set-buffer gnus-summary-buffer)
2648 gnus-current-headers)))
2649 (message-fetch-field "date")
2651 (date (if (vectorp header) (mail-header-date header)
2653 (inhibit-point-motion-hooks t)
2654 bface eface date-pos)
2655 (when (and date (not (string= date "")))
2658 (article-narrow-to-head)
2659 (when (or (and (eq type 'lapsed)
2660 gnus-article-date-lapsed-new-header
2661 ;; Attempt to get the face of X-Sent first.
2662 (re-search-forward "^X-Sent:[ \t]" nil t))
2663 (re-search-forward "^Date:[ \t]" nil t)
2664 ;; If Date is missing, try again for X-Sent.
2665 (re-search-forward "^X-Sent:[ \t]" nil t))
2666 (setq bface (get-text-property (gnus-point-at-bol) 'face)
2667 date (or (get-text-property (gnus-point-at-bol)
2670 eface (get-text-property (1- (gnus-point-at-eol))
2672 (let ((buffer-read-only nil))
2673 ;; Delete any old X-Sent headers.
2674 (when (setq date-pos
2675 (text-property-any (point-min) (point-max)
2676 'article-date-lapsed t))
2677 (goto-char (setq date-pos (set-marker (make-marker) date-pos)))
2678 (delete-region (match-beginning 0)
2679 (progn (forward-line 1) (point))))
2680 (goto-char (point-min))
2681 ;; Delete any old Date headers.
2682 (while (re-search-forward "^Date:[ \t]" nil t)
2684 (setq date-pos (match-beginning 0)))
2685 (unless (and (eq type 'lapsed)
2686 gnus-article-date-lapsed-new-header)
2687 (delete-region (match-beginning 0)
2688 (progn (message-next-header) (point)))))
2691 (goto-char date-pos)
2693 ;; Possibly, Date has been deleted.
2695 (when (and (eq type 'lapsed)
2696 gnus-article-date-lapsed-new-header
2697 (looking-at "Date:"))
2699 (goto-char (point-min)))
2700 (insert (article-make-date-line date type))
2701 (when (eq type 'lapsed)
2702 (put-text-property (gnus-point-at-bol) (point)
2703 'article-date-lapsed t))
2707 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
2708 (put-text-property (match-beginning 1) (1+ (match-end 1))
2709 'original-date date)
2710 (put-text-property (match-beginning 1) (1+ (match-end 1))
2712 (put-text-property (match-beginning 2) (match-end 2)
2715 (defun article-make-date-line (date type)
2716 "Return a DATE line of TYPE."
2717 (unless (memq type '(local ut original user iso8601 lapsed english))
2718 (error "Unknown conversion type: %s" type))
2720 (let ((time (date-to-time date)))
2722 ;; Convert to the local timezone.
2724 (let ((tz (car (current-time-zone time))))
2725 (format "Date: %s %s%02d%02d" (current-time-string time)
2726 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2727 (/ (% (abs tz) 3600) 60))))
2728 ;; Convert to Universal Time.
2731 (current-time-string
2732 (let* ((e (parse-time-string date))
2733 (tm (apply 'encode-time e))
2735 (ls (- (cadr tm) (car (current-time-zone time)))))
2736 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
2737 ((> ls 65535) (list (1+ ms) (- ls 65536)))
2740 ;; Get the original date from the article.
2741 ((eq type 'original)
2742 (concat "Date: " (if (string-match "\n+$" date)
2743 (substring date 0 (match-beginning 0))
2745 ;; Let the user define the format.
2747 (if (gnus-functionp gnus-article-time-format)
2748 (funcall gnus-article-time-format time)
2751 (format-time-string gnus-article-time-format time))))
2754 (let ((tz (car (current-time-zone time))))
2757 (format-time-string "%Y%m%dT%H%M%S" time)
2758 (format "%s%02d%02d"
2759 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2760 (/ (% (abs tz) 3600) 60)))))
2761 ;; Do an X-Sent lapsed format.
2763 ;; If the date is seriously mangled, the timezone functions are
2764 ;; liable to bug out, so we ignore all errors.
2765 (let* ((now (current-time))
2766 (real-time (subtract-time now time))
2767 (real-sec (and real-time
2768 (+ (* (float (car real-time)) 65536)
2770 (sec (and real-time (abs real-sec)))
2780 ;; This is a bit convoluted, but basically we go
2781 ;; through the time units for years, weeks, etc,
2782 ;; and divide things to see whether that results
2783 ;; in positive answers.
2786 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
2787 ;; The (remaining) seconds are too few to
2788 ;; be divided into this time unit.
2790 ;; It's big enough, so we output it.
2791 (setq sec (- sec (* num (cdr unit))))
2793 (concat (if prev ", " "") (int-to-string
2795 " " (symbol-name (car unit))
2796 (if (> num 1) "s" ""))
2798 article-time-units "")
2799 ;; If dates are odd, then it might appear like the
2800 ;; article was sent in the future.
2803 " in the future"))))))
2804 ;; Display the date in proper English
2806 (let ((dtime (decode-time time)))
2809 (number-to-string (nth 3 dtime))
2810 (let ((digit (% (nth 3 dtime) 10)))
2812 ((memq (nth 3 dtime) '(11 12 13)) "th")
2818 (nth (1- (nth 4 dtime)) gnus-english-month-names)
2820 (number-to-string (nth 5 dtime))
2822 (format "%02d" (nth 2 dtime))
2824 (format "%02d" (nth 1 dtime)))))))
2826 (format "Date: %s (from Oort)" date))))
2828 (defun article-date-local (&optional highlight)
2829 "Convert the current article date to the local timezone."
2830 (interactive (list t))
2831 (article-date-ut 'local highlight))
2833 (defun article-date-english (&optional highlight)
2834 "Convert the current article date to something that is proper English."
2835 (interactive (list t))
2836 (article-date-ut 'english highlight))
2838 (defun article-date-original (&optional highlight)
2839 "Convert the current article date to what it was originally.
2840 This is only useful if you have used some other date conversion
2841 function and want to see what the date was before converting."
2842 (interactive (list t))
2843 (article-date-ut 'original highlight))
2845 (defun article-date-lapsed (&optional highlight)
2846 "Convert the current article date to time lapsed since it was sent."
2847 (interactive (list t))
2848 (article-date-ut 'lapsed highlight))
2850 (defun article-update-date-lapsed ()
2851 "Function to be run from a timer to update the lapsed time line."
2852 (let (deactivate-mark)
2857 (set-buffer (window-buffer w))
2858 (when (eq major-mode 'gnus-article-mode)
2859 (goto-char (point-min))
2860 (when (re-search-forward "^X-Sent:" nil t)
2861 (article-date-lapsed t))))
2864 (defun gnus-start-date-timer (&optional n)
2865 "Start a timer to update the X-Sent header in the article buffers.
2866 The numerical prefix says how frequently (in seconds) the function
2871 (gnus-stop-date-timer)
2872 (setq article-lapsed-timer
2873 (nnheader-run-at-time 1 n 'article-update-date-lapsed)))
2875 (defun gnus-stop-date-timer ()
2876 "Stop the X-Sent timer."
2878 (when article-lapsed-timer
2879 (nnheader-cancel-timer article-lapsed-timer)
2880 (setq article-lapsed-timer nil)))
2882 (defun article-date-user (&optional highlight)
2883 "Convert the current article date to the user-defined format.
2884 This format is defined by the `gnus-article-time-format' variable."
2885 (interactive (list t))
2886 (article-date-ut 'user highlight))
2888 (defun article-date-iso8601 (&optional highlight)
2889 "Convert the current article date to ISO8601."
2890 (interactive (list t))
2891 (article-date-ut 'iso8601 highlight))
2893 ;; (defun article-show-all ()
2894 ;; "Show all hidden text in the article buffer."
2898 ;; (let ((buffer-read-only nil))
2899 ;; (gnus-article-unhide-text (point-min) (point-max))
2900 ;; (gnus-remove-text-with-property 'gnus-prev)
2901 ;; (gnus-remove-text-with-property 'gnus-next))))
2903 (defun article-show-all-headers ()
2904 "Show all hidden headers in the article buffer."
2909 (article-narrow-to-head)
2910 (let ((buffer-read-only nil))
2911 (gnus-article-unhide-text (point-min) (point-max))))))
2913 (defun article-remove-leading-whitespace ()
2914 "Remove excessive whitespace from all headers."
2918 (let ((buffer-read-only nil))
2919 (article-narrow-to-head)
2920 (goto-char (point-min))
2921 (while (re-search-forward "^[^ :]+: \\([ \t]+\\)" nil t)
2922 (delete-region (match-beginning 1) (match-end 1)))))))
2924 (defun article-emphasize (&optional arg)
2925 "Emphasize text according to `gnus-emphasis-alist'."
2926 (interactive (gnus-article-hidden-arg))
2927 (unless (gnus-article-check-hidden-text 'emphasis arg)
2931 (with-current-buffer gnus-summary-buffer
2932 gnus-article-emphasis-alist)
2934 gnus-emphasis-alist))
2935 (buffer-read-only nil)
2936 (props (append '(article-type emphasis)
2937 gnus-hidden-properties))
2938 regexp elem beg invisible visible face)
2941 (while (setq elem (pop alist))
2943 (setq regexp (car elem)
2944 invisible (nth 1 elem)
2945 visible (nth 2 elem)
2947 (while (re-search-forward regexp nil t)
2948 (when (and (match-beginning visible) (match-beginning invisible))
2949 (gnus-article-hide-text
2950 (match-beginning invisible) (match-end invisible) props)
2951 (gnus-article-unhide-text-type
2952 (match-beginning visible) (match-end visible) 'emphasis)
2953 (gnus-put-overlay-excluding-newlines
2954 (match-beginning visible) (match-end visible) 'face face)
2955 (gnus-add-wash-type 'emphasis)
2956 (goto-char (match-end invisible)))))))))
2958 (defun gnus-article-setup-highlight-words (&optional highlight-words)
2959 "Setup newsgroup emphasis alist."
2960 (unless gnus-article-emphasis-alist
2961 (let ((name (and gnus-newsgroup-name
2962 (gnus-group-real-name gnus-newsgroup-name))))
2963 (make-local-variable 'gnus-article-emphasis-alist)
2964 (setq gnus-article-emphasis-alist
2966 (let ((alist gnus-group-highlight-words-alist) elem highlight)
2967 (while (setq elem (pop alist))
2968 (when (and name (string-match (car elem) name))
2970 highlight (copy-sequence (cdr elem)))))
2972 (copy-sequence highlight-words)
2973 (if gnus-newsgroup-name
2974 (copy-sequence (gnus-group-find-parameter
2975 gnus-newsgroup-name 'highlight-words t)))
2976 gnus-emphasis-alist)))))
2979 (defvar gnus-summary-article-menu)
2980 (defvar gnus-summary-post-menu))
2982 ;;; Saving functions.
2984 (defun gnus-article-save (save-buffer file &optional num)
2985 "Save the currently selected article."
2986 (unless gnus-save-all-headers
2987 ;; Remove headers according to `gnus-saved-headers'.
2988 (let ((gnus-visible-headers
2989 (or gnus-saved-headers gnus-visible-headers))
2990 (gnus-article-buffer save-buffer))
2992 (set-buffer save-buffer)
2993 (article-hide-headers 1 t))))
2994 (save-window-excursion
2995 (if (not gnus-default-article-saver)
2996 (error "No default saver is defined")
2997 ;; !!! Magic! The saving functions all save
2998 ;; `gnus-save-article-buffer' (or so they think), but we
2999 ;; bind that variable to our save-buffer.
3000 (set-buffer gnus-article-buffer)
3001 (let* ((gnus-save-article-buffer save-buffer)
3004 ((not gnus-prompt-before-saving) 'default)
3005 ((eq gnus-prompt-before-saving 'always) nil)
3007 (gnus-number-of-articles-to-be-saved
3008 (when (eq gnus-prompt-before-saving t)
3010 (set-buffer gnus-article-current-summary)
3011 (funcall gnus-default-article-saver filename)))))
3013 (defun gnus-read-save-file-name (prompt &optional filename
3014 function group headers variable)
3016 (funcall function group headers (symbol-value variable)))
3021 ((eq filename 'default)
3027 (let* ((split-name (gnus-get-split-value gnus-split-methods))
3030 (if (and gnus-number-of-articles-to-be-saved
3031 (> gnus-number-of-articles-to-be-saved 1))
3032 (format "these %d articles"
3033 gnus-number-of-articles-to-be-saved)
3036 ;; Let the split methods have their say.
3038 ;; No split name was found.
3041 (concat prompt " (default "
3042 (file-name-nondirectory default-name) ") ")
3043 (file-name-directory default-name)
3045 ;; A single group name is returned.
3046 ((stringp split-name)
3048 (funcall function split-name headers
3049 (symbol-value variable)))
3051 (concat prompt " (default "
3052 (file-name-nondirectory default-name) ") ")
3053 (file-name-directory default-name)
3055 ;; A single split name was found
3056 ((= 1 (length split-name))
3057 (let* ((name (expand-file-name
3059 gnus-article-save-directory))
3060 (dir (cond ((file-directory-p name)
3061 (file-name-as-directory name))
3062 ((file-exists-p name) name)
3063 (t gnus-article-save-directory))))
3065 (concat prompt " (default " name ") ")
3067 ;; A list of splits was found.
3069 (setq split-name (nreverse split-name))
3071 (let ((file-name-history
3072 (nconc split-name file-name-history)))
3076 (concat prompt " (`M-p' for defaults) ")
3077 gnus-article-save-directory
3079 gnus-article-save-directory)))
3080 (car (push result file-name-history)))))))
3081 ;; Create the directory.
3082 (gnus-make-directory (file-name-directory file))
3083 ;; If we have read a directory, we append the default file name.
3084 (when (file-directory-p file)
3085 (setq file (expand-file-name (file-name-nondirectory
3087 (file-name-as-directory file))))
3088 ;; Possibly translate some characters.
3089 (nnheader-translate-file-chars file))))))
3090 (gnus-make-directory (file-name-directory result))
3091 (set variable result)))
3093 (defun gnus-article-archive-name (group)
3094 "Return the first instance of an \"Archive-name\" in the current buffer."
3095 (let ((case-fold-search t))
3096 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
3097 (nnheader-concat gnus-article-save-directory
3098 (match-string 1)))))
3100 (defun gnus-article-nndoc-name (group)
3101 "If GROUP is an nndoc group, return the name of the parent group."
3102 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
3103 (gnus-group-get-parameter group 'save-article-group)))
3105 (defun gnus-summary-save-in-rmail (&optional filename)
3106 "Append this article to Rmail file.
3107 Optional argument FILENAME specifies file name.
3108 Directory to save to is default to `gnus-article-save-directory'."
3109 (setq filename (gnus-read-save-file-name
3110 "Save %s in rmail file:" filename
3111 gnus-rmail-save-name gnus-newsgroup-name
3112 gnus-current-headers 'gnus-newsgroup-last-rmail))
3113 (gnus-eval-in-buffer-window gnus-save-article-buffer
3117 (gnus-output-to-rmail filename))))
3120 (defun gnus-summary-save-in-mail (&optional filename)
3121 "Append this article to Unix mail file.
3122 Optional argument FILENAME specifies file name.
3123 Directory to save to is default to `gnus-article-save-directory'."
3124 (setq filename (gnus-read-save-file-name
3125 "Save %s in Unix mail file:" filename
3126 gnus-mail-save-name gnus-newsgroup-name
3127 gnus-current-headers 'gnus-newsgroup-last-mail))
3128 (gnus-eval-in-buffer-window gnus-save-article-buffer
3132 (if (and (file-readable-p filename)
3133 (mail-file-babyl-p filename))
3134 (rmail-output-to-rmail-file filename t)
3135 (gnus-output-to-mail filename)))))
3138 (defun gnus-summary-save-in-file (&optional filename overwrite)
3139 "Append this article to file.
3140 Optional argument FILENAME specifies file name.
3141 Directory to save to is default to `gnus-article-save-directory'."
3142 (setq filename (gnus-read-save-file-name
3143 "Save %s in file:" filename
3144 gnus-file-save-name gnus-newsgroup-name
3145 gnus-current-headers 'gnus-newsgroup-last-file))
3146 (gnus-eval-in-buffer-window gnus-save-article-buffer
3150 (when (and overwrite
3151 (file-exists-p filename))
3152 (delete-file filename))
3153 (gnus-output-to-file filename))))
3156 (defun gnus-summary-write-to-file (&optional filename)
3157 "Write this article to a file, overwriting it if the file exists.
3158 Optional argument FILENAME specifies file name.
3159 The directory to save in defaults to `gnus-article-save-directory'."
3160 (gnus-summary-save-in-file nil t))
3162 (defun gnus-summary-save-body-in-file (&optional filename)
3163 "Append this article body to a file.
3164 Optional argument FILENAME specifies file name.
3165 The directory to save in defaults to `gnus-article-save-directory'."
3166 (setq filename (gnus-read-save-file-name
3167 "Save %s body in file:" filename
3168 gnus-file-save-name gnus-newsgroup-name
3169 gnus-current-headers 'gnus-newsgroup-last-file))
3170 (gnus-eval-in-buffer-window gnus-save-article-buffer
3174 (when (article-goto-body)
3175 (narrow-to-region (point) (point-max)))
3176 (gnus-output-to-file filename))))
3179 (defun gnus-summary-save-in-pipe (&optional command)
3180 "Pipe this article to subprocess."
3182 (cond ((and (eq command 'default)
3183 gnus-last-shell-command)
3184 gnus-last-shell-command)
3189 "Shell command on %s: "
3190 (if (and gnus-number-of-articles-to-be-saved
3191 (> gnus-number-of-articles-to-be-saved 1))
3192 (format "these %d articles"
3193 gnus-number-of-articles-to-be-saved)
3195 gnus-last-shell-command))))
3196 (when (string-equal command "")
3197 (if gnus-last-shell-command
3198 (setq command gnus-last-shell-command)
3199 (error "A command is required")))
3200 (gnus-eval-in-buffer-window gnus-article-buffer
3203 (shell-command-on-region (point-min) (point-max) command nil)))
3204 (setq gnus-last-shell-command command))
3206 (defun gnus-summary-pipe-to-muttprint (&optional command)
3207 "Pipe this article to muttprint."
3208 (setq command (read-string
3209 "Print using command: " gnus-summary-muttprint-program
3210 nil gnus-summary-muttprint-program))
3211 (gnus-summary-save-in-pipe command))
3213 ;;; Article file names when saving.
3215 (defun gnus-capitalize-newsgroup (newsgroup)
3216 "Capitalize NEWSGROUP name."
3217 (when (not (zerop (length newsgroup)))
3218 (concat (char-to-string (upcase (aref newsgroup 0)))
3219 (substring newsgroup 1))))
3221 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
3222 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
3223 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
3224 Otherwise, it is like ~/News/news/group/num."
3227 (concat (if (gnus-use-long-file-name 'not-save)
3228 (gnus-capitalize-newsgroup newsgroup)
3229 (gnus-newsgroup-directory-form newsgroup))
3230 "/" (int-to-string (mail-header-number headers)))
3231 gnus-article-save-directory)))
3233 (string-equal (file-name-directory default)
3234 (file-name-directory last-file))
3235 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
3237 (or last-file default))))
3239 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
3240 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
3241 If variable `gnus-use-long-file-name' is non-nil, it is
3242 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
3245 (concat (if (gnus-use-long-file-name 'not-save)
3247 (gnus-newsgroup-directory-form newsgroup))
3248 "/" (int-to-string (mail-header-number headers)))
3249 gnus-article-save-directory)))
3251 (string-equal (file-name-directory default)
3252 (file-name-directory last-file))
3253 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
3255 (or last-file default))))
3257 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
3258 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
3259 If variable `gnus-use-long-file-name' is non-nil, it is
3260 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
3263 (if (gnus-use-long-file-name 'not-save)
3266 (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup))
3268 gnus-article-save-directory)))
3270 (defun gnus-sender-save-name (newsgroup headers &optional last-file)
3271 "Generate file name from sender."
3272 (let ((from (mail-header-from headers)))
3274 (if (and from (string-match "\\([^ <]+\\)@" from))
3275 (match-string 1 from)
3277 gnus-article-save-directory)))
3279 (defun article-verify-x-pgp-sig ()
3282 (if (gnus-buffer-live-p gnus-original-article-buffer)
3283 (let ((sig (with-current-buffer gnus-original-article-buffer
3284 (gnus-fetch-field "X-PGP-Sig")))
3288 (mml2015-clear-verify-function))
3290 (insert-buffer gnus-original-article-buffer)
3291 (setq items (split-string sig))
3292 (message-narrow-to-head)
3293 (let ((inhibit-point-motion-hooks t)
3294 (case-fold-search t))
3295 ;; Don't verify multiple headers.
3296 (setq headers (mapconcat (lambda (header)
3298 (mail-fetch-field header) "\n"))
3299 (split-string (nth 1 items) ",") "")))
3300 (delete-region (point-min) (point-max))
3301 (insert "-----BEGIN PGP SIGNED MESSAGE-----\n\n")
3302 (insert "X-Signed-Headers: " (nth 1 items) "\n")
3307 (if (looking-at "^-")
3310 (insert "\n-----BEGIN PGP SIGNATURE-----\n")
3311 (insert "Version: " (car items) "\n\n")
3312 (insert (mapconcat 'identity (cddr items) "\n"))
3313 (insert "\n-----END PGP SIGNATURE-----\n")
3314 (let ((mm-security-handle (list (format "multipart/signed"))))
3315 (mml2015-clean-buffer)
3316 (let ((coding-system-for-write (or gnus-newsgroup-charset
3318 (funcall (mml2015-clear-verify-function)))
3320 (or (mm-handle-multipart-ctl-parameter
3321 mm-security-handle 'gnus-details)
3322 (mm-handle-multipart-ctl-parameter
3323 mm-security-handle 'gnus-info)))))
3325 (let (buffer-read-only bface eface)
3327 (message-narrow-to-head)
3328 (goto-char (point-max))
3330 (setq bface (get-text-property (gnus-point-at-bol) 'face)
3331 eface (get-text-property (1- (gnus-point-at-eol)) 'face))
3332 (message-remove-header "X-Gnus-PGP-Verify")
3333 (if (re-search-forward "^X-PGP-Sig:" nil t)
3335 (goto-char (point-max)))
3336 (narrow-to-region (point) (point))
3337 (insert "X-Gnus-PGP-Verify: " info "\n")
3338 (goto-char (point-min))
3341 (if (not (looking-at "^[ \t]"))
3345 (goto-char (point-min))
3346 (when (looking-at "\\([^:]+\\): *")
3347 (put-text-property (match-beginning 1) (1+ (match-end 1))
3349 (put-text-property (match-end 0) (point-max)
3350 'face eface)))))))))
3352 (defun article-verify-cancel-lock ()
3353 "Verify Cancel-Lock header."
3355 (if (gnus-buffer-live-p gnus-original-article-buffer)
3356 (canlock-verify gnus-original-article-buffer)))
3363 (setq afunc (car func)
3366 gfunc (intern (format "gnus-%s" func))))
3368 (when (fboundp afunc)
3369 `(lambda (&optional interactive &rest args)
3370 ,(documentation afunc t)
3371 (interactive (list t))
3373 (set-buffer gnus-article-buffer)
3375 (call-interactively ',afunc)
3376 (apply ',afunc args))))))))
3377 '(article-hide-headers
3378 article-verify-x-pgp-sig
3379 article-verify-cancel-lock
3380 article-hide-boring-headers
3381 article-toggle-headers
3382 article-treat-overstrike
3383 article-fill-long-lines
3384 article-capitalize-sentences
3386 article-remove-leading-whitespace
3387 article-display-x-face
3388 article-de-quoted-unreadable
3389 article-de-base64-unreadable
3392 article-hide-list-identifiers
3394 article-strip-banner
3397 article-hide-signature
3398 article-strip-headers-in-body
3399 article-remove-trailing-blank-lines
3400 article-strip-leading-blank-lines
3401 article-strip-multiple-blank-lines
3402 article-strip-leading-space
3403 article-strip-trailing-space
3404 article-strip-blank-lines
3405 article-strip-all-blank-lines
3407 article-date-english
3408 article-date-iso8601
3409 article-date-original
3411 article-decode-mime-words
3412 article-decode-charset
3413 article-decode-encoded-words
3417 article-treat-dumbquotes
3418 article-normalize-headers
3419 (article-show-all-headers . gnus-article-show-all-headers)
3420 ;; (article-show-all . gnus-article-show-all)
3424 ;;; Gnus article mode
3427 (put 'gnus-article-mode 'mode-class 'special)
3429 (gnus-define-keys gnus-article-mode-map
3430 " " gnus-article-goto-next-page
3431 "\177" gnus-article-goto-prev-page
3432 [delete] gnus-article-goto-prev-page
3433 [backspace] gnus-article-goto-prev-page
3434 "\C-c^" gnus-article-refer-article
3435 "h" gnus-article-show-summary
3436 "s" gnus-article-show-summary
3437 "\C-c\C-m" gnus-article-mail
3438 "?" gnus-article-describe-briefly
3439 "e" gnus-summary-edit-article
3440 "<" beginning-of-buffer
3442 "\C-c\C-i" gnus-info-find-node
3444 "R" gnus-article-reply-with-original
3445 "F" gnus-article-followup-with-original
3446 "\C-hk" gnus-article-describe-key
3447 "\C-hc" gnus-article-describe-key-briefly
3449 "\C-d" gnus-article-read-summary-keys
3450 "\M-*" gnus-article-read-summary-keys
3451 "\M-#" gnus-article-read-summary-keys
3452 "\M-^" gnus-article-read-summary-keys
3453 "\M-g" gnus-article-read-summary-keys)
3455 ;; Define almost undefined keys to `gnus-article-read-summary-keys'.
3459 (push (char-to-string key) keys)
3461 (dolist (elem (accessible-keymaps gnus-summary-mode-map))
3462 (setq key (car elem))
3463 (when (and (> (length key) 0)
3464 (not (eq 'menu-bar (aref key 0)))
3465 (symbolp (lookup-key gnus-summary-mode-map key)))
3468 (unless (lookup-key gnus-article-mode-map key)
3469 (define-key gnus-article-mode-map key 'gnus-article-read-summary-keys))))
3471 (defun gnus-article-make-menu-bar ()
3472 (unless (boundp 'gnus-article-commands-menu)
3473 (gnus-summary-make-menu-bar))
3474 (gnus-turn-off-edit-menu 'article)
3475 (unless (boundp 'gnus-article-article-menu)
3477 gnus-article-article-menu gnus-article-mode-map ""
3479 ["Scroll forwards" gnus-article-goto-next-page t]
3480 ["Scroll backwards" gnus-article-goto-prev-page t]
3481 ["Show summary" gnus-article-show-summary t]
3482 ["Fetch Message-ID at point" gnus-article-refer-article t]
3483 ["Mail to address at point" gnus-article-mail t]
3484 ["Send a bug report" gnus-bug t]))
3487 gnus-article-treatment-menu gnus-article-mode-map ""
3488 ;; Fixme: this should use :active (and maybe :visible).
3490 ["Hide headers" gnus-article-toggle-headers t]
3491 ["Hide signature" gnus-article-hide-signature t]
3492 ["Hide citation" gnus-article-hide-citation t]
3493 ["Treat overstrike" gnus-article-treat-overstrike t]
3494 ["Remove carriage return" gnus-article-remove-cr t]
3495 ["Remove leading whitespace" gnus-article-remove-leading-whitespace t]
3496 ["Decode HZ" gnus-article-decode-HZ t]))
3498 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
3500 ;; Note "Post" menu is defined in gnus-sum.el for consistency
3502 (gnus-run-hooks 'gnus-article-menu-hook)))
3504 ;; Fixme: do something for the Emacs tool bar in Article mode a la
3507 (defun gnus-article-mode ()
3508 "Major mode for displaying an article.
3510 All normal editing commands are switched off.
3512 The following commands are available in addition to all summary mode
3514 \\<gnus-article-mode-map>
3515 \\[gnus-article-next-page]\t Scroll the article one page forwards
3516 \\[gnus-article-prev-page]\t Scroll the article one page backwards
3517 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
3518 \\[gnus-article-show-summary]\t Display the summary buffer
3519 \\[gnus-article-mail]\t Send a reply to the address near point
3520 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
3521 \\[gnus-info-find-node]\t Go to the Gnus info node"
3523 (gnus-simplify-mode-line)
3524 (setq mode-name "Article")
3525 (setq major-mode 'gnus-article-mode)
3526 (make-local-variable 'minor-mode-alist)
3527 (unless (assq 'gnus-show-mime minor-mode-alist)
3528 (push (list 'gnus-show-mime " MIME") minor-mode-alist))
3529 (use-local-map gnus-article-mode-map)
3530 (when (gnus-visual-p 'article-menu 'menu)
3531 (gnus-article-make-menu-bar))
3532 (gnus-update-format-specifications nil 'article-mode)
3533 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
3534 (make-local-variable 'gnus-page-broken)
3535 (make-local-variable 'gnus-button-marker-list)
3536 (make-local-variable 'gnus-article-current-summary)
3537 (make-local-variable 'gnus-article-mime-handles)
3538 (make-local-variable 'gnus-article-decoded-p)
3539 (make-local-variable 'gnus-article-mime-handle-alist)
3540 (make-local-variable 'gnus-article-wash-types)
3541 (make-local-variable 'gnus-article-image-alist)
3542 (make-local-variable 'gnus-article-charset)
3543 (make-local-variable 'gnus-article-ignored-charsets)
3544 (gnus-set-default-directory)
3545 (buffer-disable-undo)
3546 (setq buffer-read-only t)
3547 (set-syntax-table gnus-article-mode-syntax-table)
3548 (gnus-run-hooks 'gnus-article-mode-hook))
3550 (defun gnus-article-setup-buffer ()
3551 "Initialize the article buffer."
3552 (let* ((name (if gnus-single-article-buffer "*Article*"
3553 (concat "*Article " gnus-newsgroup-name "*")))
3555 (progn (string-match "\\*Article" name)
3556 (concat " *Original Article"
3557 (substring name (match-end 0))))))
3558 (setq gnus-article-buffer name)
3559 (setq gnus-original-article-buffer original)
3560 (setq gnus-article-mime-handle-alist nil)
3561 ;; This might be a variable local to the summary buffer.
3562 (unless gnus-single-article-buffer
3564 (set-buffer gnus-summary-buffer)
3565 (setq gnus-article-buffer name)
3566 (setq gnus-original-article-buffer original)
3567 (gnus-set-global-variables)))
3568 (gnus-article-setup-highlight-words)
3569 ;; Init original article buffer.
3571 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
3572 (set-buffer-multibyte nil)
3573 (setq major-mode 'gnus-original-article-mode)
3574 (make-local-variable 'gnus-original-article))
3575 (if (get-buffer name)
3578 (buffer-disable-undo)
3579 (setq buffer-read-only t)
3580 (unless (eq major-mode 'gnus-article-mode)
3581 (gnus-article-mode))
3584 (set-buffer (gnus-get-buffer-create name))
3586 (make-local-variable 'gnus-summary-buffer)
3587 (gnus-summary-set-local-parameters gnus-newsgroup-name)
3588 (current-buffer)))))
3590 ;; Set article window start at LINE, where LINE is the number of lines
3591 ;; from the head of the article.
3592 (defun gnus-article-set-window-start (&optional line)
3594 (gnus-get-buffer-window gnus-article-buffer t)
3596 (set-buffer gnus-article-buffer)
3597 (goto-char (point-min))
3600 (gnus-message 6 "Moved to bookmark")
3601 (search-forward "\n\n" nil t)
3605 ;;; @@ article filters
3608 (defun gnus-article-display-mime-message ()
3609 "Article display method for MIME message."
3610 ;; called from `gnus-original-article-buffer'.
3611 (let (charset all-headers)
3612 (with-current-buffer gnus-summary-buffer
3613 (setq charset default-mime-charset
3614 all-headers gnus-have-all-headers))
3615 (make-local-variable 'default-mime-charset)
3616 (setq default-mime-charset charset)
3617 (with-current-buffer (get-buffer-create gnus-article-buffer)
3618 (make-local-variable 'default-mime-charset)
3619 (setq default-mime-charset charset))
3620 (mime-display-message mime-message-structure
3621 gnus-article-buffer nil gnus-article-mode-map)
3623 (gnus-article-hide-headers nil -1)))
3624 (run-hooks 'gnus-mime-article-prepare-hook))
3626 (defun gnus-article-display-traditional-message ()
3627 "Article display method for traditional message."
3628 (set-buffer gnus-article-buffer)
3629 (let (buffer-read-only)
3631 (set-buffer-multibyte nil)
3632 (insert-buffer-substring gnus-original-article-buffer)
3633 (set-buffer-multibyte t)))
3635 (defun gnus-article-make-full-mail-header (&optional number charset)
3636 "Create a new mail header structure in a raw article buffer."
3637 (unless (and number charset)
3638 (save-current-buffer
3639 (set-buffer gnus-summary-buffer)
3641 (setq number (or (cdr gnus-article-current) 0)))
3643 (setq charset (or default-mime-charset 'x-ctext)))))
3644 (goto-char (point-min))
3645 (let ((header-end (if (search-forward "\n\n" nil t)
3647 (goto-char (point-max))))
3648 (chars (- (point-max) (point)))
3649 (lines (count-lines (point) (point-max)))
3650 (default-mime-charset charset)
3652 (narrow-to-region (point-min) header-end)
3653 (setq xref (std11-fetch-field "xref"))
3655 (make-full-mail-header
3657 (std11-fetch-field "subject")
3658 (std11-fetch-field "from")
3659 (std11-fetch-field "date")
3660 (std11-fetch-field "message-id")
3661 (std11-fetch-field "references")
3664 (when xref (concat "Xref: " xref)))
3667 (defun gnus-article-prepare (article &optional all-headers header)
3668 "Prepare ARTICLE in article mode buffer.
3669 ARTICLE should either be an article number or a Message-ID.
3670 If ARTICLE is an id, HEADER should be the article headers.
3671 If ALL-HEADERS is non-nil, no headers are hidden."
3673 ;; Make sure we start in a summary buffer.
3674 (unless (eq major-mode 'gnus-summary-mode)
3675 (set-buffer gnus-summary-buffer))
3676 (setq gnus-summary-buffer (current-buffer))
3677 (let* ((gnus-article (if header (mail-header-number header) article))
3678 (summary-buffer (current-buffer))
3679 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
3680 (group gnus-newsgroup-name)
3683 (gnus-article-setup-buffer)
3684 (set-buffer gnus-article-buffer)
3685 ;; Deactivate active regions.
3686 (when (and (boundp 'transient-mark-mode)
3687 transient-mark-mode)
3688 (setq mark-active nil))
3689 (if (not (setq result (let ((buffer-read-only nil))
3690 (gnus-request-article-this-buffer
3692 ;; There is no such article.
3694 (when (and (numberp article)
3695 (not (memq article gnus-newsgroup-sparse)))
3696 (setq gnus-article-current
3697 (cons gnus-newsgroup-name article))
3698 (set-buffer gnus-summary-buffer)
3699 (setq gnus-current-article article)
3700 (if (eq (gnus-article-mark article) gnus-undownloaded-mark)
3702 (gnus-summary-set-agent-mark article)
3703 (message "Message marked for downloading"))
3704 (gnus-summary-mark-article article gnus-canceled-mark)
3705 (unless (memq article gnus-newsgroup-sparse)
3706 (gnus-error 1 "No such article (may have expired or been canceled)")))))
3707 (if (or (eq result 'pseudo)
3708 (eq result 'nneething))
3711 (set-buffer summary-buffer)
3712 (push article gnus-newsgroup-history)
3713 (setq gnus-last-article gnus-current-article
3714 gnus-current-article 0
3715 gnus-current-headers nil
3716 gnus-article-current nil)
3717 (if (eq result 'nneething)
3718 (gnus-configure-windows 'summary)
3719 (gnus-configure-windows 'article))
3720 (gnus-set-global-variables))
3721 (let ((gnus-article-mime-handle-alist-1
3722 gnus-article-mime-handle-alist))
3723 (gnus-set-mode-line 'article)))
3724 ;; The result from the `request' was an actual article -
3725 ;; or at least some text that is now displayed in the
3727 (when (and (numberp article)
3728 (not (eq article gnus-current-article)))
3729 ;; Seems like a new article has been selected.
3730 ;; `gnus-current-article' must be an article number.
3732 (set-buffer summary-buffer)
3733 (push article gnus-newsgroup-history)
3734 (setq gnus-last-article gnus-current-article
3735 gnus-current-article article
3736 gnus-current-headers
3737 (gnus-summary-article-header gnus-current-article)
3738 gnus-article-current
3739 (cons gnus-newsgroup-name gnus-current-article))
3740 (unless (vectorp gnus-current-headers)
3741 (setq gnus-current-headers nil))
3742 (gnus-summary-goto-subject gnus-current-article)
3743 (when (gnus-summary-show-thread)
3744 ;; If the summary buffer really was folded, the
3745 ;; previous goto may not actually have gone to
3746 ;; the right article, but the thread root instead.
3748 (gnus-summary-goto-subject gnus-current-article))
3749 (gnus-run-hooks 'gnus-mark-article-hook)
3750 (gnus-set-mode-line 'summary)
3751 (when (gnus-visual-p 'article-highlight 'highlight)
3752 (gnus-run-hooks 'gnus-visual-mark-article-hook))
3753 ;; Set the global newsgroup variables here.
3754 (gnus-set-global-variables)
3755 (setq gnus-have-all-headers
3756 (or all-headers gnus-show-all-headers))))
3758 (gnus-configure-windows 'article))
3759 (when (or (numberp article)
3761 (gnus-article-prepare-display)
3763 (goto-char (point-min))
3764 (setq gnus-page-broken
3765 (when gnus-break-pages
3766 (gnus-narrow-to-page)
3768 (let ((gnus-article-mime-handle-alist-1
3769 gnus-article-mime-handle-alist))
3770 (gnus-set-mode-line 'article))
3772 (set-window-point (get-buffer-window (current-buffer)) (point))
3773 (gnus-configure-windows 'article)
3776 (defun gnus-article-prepare-mime-display (&optional number)
3777 (goto-char (point-min))
3778 (when (re-search-forward "^[^\t ]+:" nil t)
3779 (goto-char (match-beginning 0)))
3780 (let ((entity (if (eq 1 (point-min))
3781 (get-text-property 1 'mime-view-entity)
3782 (get-text-property (point) 'mime-view-entity)))
3783 last-entity child-entity next type)
3784 (setq child-entity (mime-entity-children entity))
3786 (setq last-entity (nth (1- (length child-entity))
3788 (setq last-entity entity))
3790 (narrow-to-region (point)
3791 (if (search-forward "\n\n" nil t)
3794 (gnus-treat-article 'head)
3795 (put-text-property (point-min) (point-max) 'article-treated-header t)
3796 (goto-char (point-max)))
3797 (while (and (not (eobp)) entity)
3798 (setq next (set-marker
3800 (next-single-property-change (point) 'mime-view-entity
3802 (let ((types (mime-entity-content-type entity)))
3803 (while (eq 'multipart (mime-content-type-primary-type types))
3804 (setq entity (car (mime-entity-children entity))
3805 types (mime-entity-content-type entity)))
3807 (setq type (format "%s/%s"
3808 (mime-content-type-primary-type types)
3809 (mime-content-type-subtype types)))))
3810 (if (string-equal type "message/rfc822")
3813 (let ((children (mime-entity-children entity))
3816 (setq last-children (nth (1- (length children)) children))
3819 (not (eq last-children
3820 (get-text-property next 'mime-view-entity)))
3822 (next-single-property-change next
3824 nil (point-max)))))))
3825 (setq next (next-single-property-change next 'mime-view-entity
3828 (narrow-to-region (point) next)
3829 (gnus-article-prepare-mime-display)
3830 (goto-char (point-max)))
3831 (setq entity (get-text-property (point) 'mime-view-entity)))
3833 (narrow-to-region (point) next)
3834 ;; Kludge. We have to count true number, but for now,
3835 ;; part number is here only to achieve `last'.
3836 (gnus-treat-article nil 1
3837 (if (eq entity last-entity)
3840 (goto-char (point-max)))
3841 (setq entity (get-text-property next 'mime-view-entity))))))
3844 (defun gnus-article-prepare-display ()
3845 "Make the current buffer look like a nice article."
3846 (let ((gnus-article-buffer (current-buffer))
3848 (unless (eq major-mode 'gnus-article-mode)
3849 (gnus-article-mode))
3850 (setq buffer-read-only nil
3851 gnus-button-marker-list nil
3852 gnus-article-wash-types nil
3853 gnus-article-image-alist nil)
3856 (static-if (featurep 'xemacs)
3857 (map-extents (lambda (extent maparg) (delete-extent extent)))
3858 (let ((lists (overlay-lists)))
3859 (dolist (overlay (nconc (car lists) (cdr lists)))
3860 (delete-overlay overlay)))))
3861 (gnus-run-hooks 'gnus-tmp-internal-hook))
3862 (set-buffer gnus-original-article-buffer)
3864 (setq mime-message-structure gnus-current-headers)
3865 (mime-buffer-entity-set-buffer-internal mime-message-structure
3866 gnus-original-article-buffer)
3867 (mime-entity-set-representation-type-internal mime-message-structure
3868 'mime-buffer-entity)
3869 (luna-send mime-message-structure 'initialize-instance
3870 mime-message-structure)
3872 (let (mime-display-header-hook mime-display-text/plain-hook)
3873 (funcall gnus-article-display-method-for-mime))
3874 (funcall gnus-article-display-method-for-traditional))
3875 ;; Call the treatment functions.
3876 (let ((inhibit-read-only t))
3880 (gnus-article-prepare-mime-display)
3881 (narrow-to-region (goto-char (point-min))
3882 (if (search-forward "\n\n" nil t)
3885 (gnus-treat-article 'head)
3886 (put-text-property (point-min) (point-max) 'article-treated-header t)
3887 (goto-char (point-max))
3889 (narrow-to-region (point) (point-max))
3890 (gnus-treat-article nil))
3891 (put-text-property (point-min) (point-max) 'read-only nil)))
3892 (gnus-run-hooks 'gnus-article-prepare-hook))
3894 (defun gnus-article-decode-article-as-default-mime-charset ()
3895 "Decode an article as `default-mime-charset'. It won't work if the
3896 value of the variable `gnus-show-mime' is non-nil."
3897 (unless gnus-show-mime
3898 (set (make-local-variable 'default-mime-charset)
3899 (with-current-buffer gnus-summary-buffer
3900 default-mime-charset))
3901 (decode-mime-charset-region (point-min) (point-max)
3902 default-mime-charset)))
3905 ;;; Gnus MIME viewing functions
3908 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
3909 "Format of the MIME buttons.
3911 Valid specifiers include:
3913 %T MIME type, along with additional info
3914 %n The `name' parameter
3915 %d The description, if any
3916 %l The length of the encoded part
3917 %p The part identifier number
3918 %e Dots if the part isn't displayed
3920 General format specifiers can also be used. See
3921 (gnus)Formatting Variables.")
3923 (defvar gnus-mime-button-line-format-alist
3924 '((?t gnus-tmp-type ?s)
3925 (?T gnus-tmp-type-long ?s)
3926 (?n gnus-tmp-name ?s)
3927 (?d gnus-tmp-description ?s)
3929 (?l gnus-tmp-length ?d)
3930 (?e gnus-tmp-dots ?s)))
3932 (defvar gnus-mime-button-commands
3933 '((gnus-article-press-button "\r" "Toggle Display")
3934 (gnus-mime-view-part "v" "View Interactively...")
3935 (gnus-mime-view-part-as-type "t" "View As Type...")
3936 (gnus-mime-view-part-as-charset "C" "View As charset...")
3937 (gnus-mime-save-part "o" "Save...")
3938 (gnus-mime-save-part-and-strip "\C-o" "Save and Strip")
3939 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
3940 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
3941 (gnus-mime-internalize-part "E" "View Internally")
3942 (gnus-mime-externalize-part "e" "View Externally")
3943 (gnus-mime-print-part "p" "Print")
3944 (gnus-mime-pipe-part "|" "Pipe To Command...")
3945 (gnus-mime-action-on-part "." "Take action on the part")))
3947 (defun gnus-article-mime-part-status ()
3948 (with-current-buffer gnus-article-buffer
3949 (let ((entity (get-text-property (point-min) 'mime-view-entity))
3952 (setq children (mime-entity-children entity))
3953 (setq children (length children)))
3956 (format " (%d parts)" children))
3959 (defvar gnus-mime-button-map
3960 (let ((map (make-sparse-keymap)))
3961 (unless (>= (string-to-number emacs-version) 21)
3962 ;; XEmacs doesn't care.
3963 (set-keymap-parent map gnus-article-mode-map))
3964 (define-key map gnus-mouse-2 'gnus-article-push-button)
3965 (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
3966 (dolist (c gnus-mime-button-commands)
3967 (define-key map (cadr c) (car c)))
3970 (defun gnus-mime-button-menu (event)
3971 "Construct a context-sensitive menu of MIME commands."
3973 (save-window-excursion
3974 (let ((pos (event-start event)))
3975 (select-window (posn-window pos))
3976 (goto-char (posn-point pos))
3977 (gnus-article-check-buffer)
3978 (let ((response (x-popup-menu
3980 ("" ,@(mapcar (lambda (c)
3981 (cons (caddr c) (car c)))
3982 gnus-mime-button-commands))))))
3984 (call-interactively response))))))
3986 (defun gnus-mime-view-all-parts (&optional handles)
3987 "View all the MIME parts."
3989 (save-current-buffer
3990 (set-buffer gnus-article-buffer)
3991 (let ((handles (or handles gnus-article-mime-handles))
3992 (mail-parse-charset gnus-newsgroup-charset)
3993 (mail-parse-ignored-charsets
3994 (with-current-buffer gnus-summary-buffer
3995 gnus-newsgroup-ignored-charsets)))
3997 (mm-remove-parts handles)
3998 (goto-char (point-min))
3999 (or (search-forward "\n\n") (goto-char (point-max)))
4000 (let (buffer-read-only)
4001 (delete-region (point) (point-max))
4002 (mm-display-parts handles))))))
4004 (defun gnus-mime-save-part-and-strip ()
4005 "Save the MIME part under point then replace it with an external body."
4007 (gnus-article-check-buffer)
4008 (let* ((data (get-text-property (point) 'gnus-data))
4010 (handles gnus-article-mime-handles))
4011 (if (mm-multiple-handles gnus-article-mime-handles)
4012 (error "This function is not implemented"))
4013 (setq file (and data (mm-save-part data)))
4015 (with-current-buffer (mm-handle-buffer data)
4017 (insert "Content-Type: " (mm-handle-media-type data))
4018 (mml-insert-parameter-string (cdr (mm-handle-type data))
4021 (insert "Content-ID: " (message-make-message-id) "\n")
4022 (insert "Content-Transfer-Encoding: binary\n")
4025 (cdr (mm-make-handle nil
4026 `("message/external-body"
4027 (access-type . "LOCAL-FILE")
4029 (set-buffer gnus-summary-buffer)
4030 (gnus-article-edit-article
4033 (let ((mail-parse-charset (or gnus-article-charset
4034 ',gnus-newsgroup-charset))
4035 (mail-parse-ignored-charsets
4036 (or gnus-article-ignored-charsets
4037 ',gnus-newsgroup-ignored-charsets))
4038 (mbl mml-buffer-list))
4039 (setq mml-buffer-list nil)
4040 (insert-buffer gnus-original-article-buffer)
4041 (mime-to-mml ',handles)
4042 (setq gnus-article-mime-handles nil)
4043 (let ((mbl1 mml-buffer-list))
4044 (setq mml-buffer-list mbl)
4045 (set (make-local-variable 'mml-buffer-list) mbl1))
4046 ;; LOCAL argument of add-hook differs between GNU Emacs
4047 ;; and XEmacs. make-local-hook makes sure they are local.
4048 (make-local-hook 'kill-buffer-hook)
4049 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
4050 `(lambda (no-highlight)
4051 (let ((mail-parse-charset (or gnus-article-charset
4052 ',gnus-newsgroup-charset))
4053 (message-options message-options)
4054 (message-options-set-recipient)
4055 (mail-parse-ignored-charsets
4056 (or gnus-article-ignored-charsets
4057 ',gnus-newsgroup-ignored-charsets)))
4059 (mml-destroy-buffers)
4060 (remove-hook 'kill-buffer-hook
4061 'mml-destroy-buffers t)
4062 (kill-local-variable 'mml-buffer-list))
4063 (gnus-summary-edit-article-done
4064 ,(or (mail-header-references gnus-current-headers) "")
4065 ,(gnus-group-read-only-p)
4066 ,gnus-summary-buffer no-highlight))))))
4068 (defun gnus-mime-save-part ()
4069 "Save the MIME part under point."
4071 (gnus-article-check-buffer)
4072 (let ((data (get-text-property (point) 'gnus-data)))
4074 (mm-save-part data))))
4076 (defun gnus-mime-pipe-part ()
4077 "Pipe the MIME part under point to a process."
4079 (gnus-article-check-buffer)
4080 (let ((data (get-text-property (point) 'gnus-data)))
4082 (mm-pipe-part data))))
4084 (defun gnus-mime-view-part ()
4085 "Interactively choose a viewing method for the MIME part under point."
4087 (gnus-article-check-buffer)
4088 (let ((data (get-text-property (point) 'gnus-data)))
4090 (setq gnus-article-mime-handles
4092 gnus-article-mime-handles (setq data (copy-sequence data))))
4093 (mm-interactively-view-part data))))
4095 (defun gnus-mime-view-part-as-type-internal ()
4096 (gnus-article-check-buffer)
4097 (let* ((name (mail-content-type-get
4098 (mm-handle-type (get-text-property (point) 'gnus-data))
4100 (def-type (and name (mm-default-file-encoding name))))
4101 (and def-type (cons def-type 0))))
4103 (defun gnus-mime-view-part-as-type (&optional mime-type)
4104 "Choose a MIME media type, and view the part as such."
4107 (setq mime-type (completing-read
4108 "View as MIME type: "
4109 (mapcar #'list (mailcap-mime-types))
4111 (gnus-mime-view-part-as-type-internal))))
4112 (gnus-article-check-buffer)
4113 (let ((handle (get-text-property (point) 'gnus-data)))
4116 (mm-make-handle (mm-handle-buffer handle)
4117 (cons mime-type (cdr (mm-handle-type handle)))
4118 (mm-handle-encoding handle)
4119 (mm-handle-undisplayer handle)
4120 (mm-handle-disposition handle)
4121 (mm-handle-description handle)
4123 (mm-handle-id handle)))
4124 (setq gnus-article-mime-handles
4125 (mm-merge-handles gnus-article-mime-handles handle))
4126 (gnus-mm-display-part handle))))
4128 (defun gnus-mime-copy-part (&optional handle)
4129 "Put the MIME part under point into a new buffer."
4131 (gnus-article-check-buffer)
4132 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4133 (contents (and handle (mm-get-part handle)))
4135 (file-name-nondirectory
4137 (mail-content-type-get (mm-handle-type handle) 'name)
4138 (mail-content-type-get (mm-handle-type handle)
4141 (buffer (and base (generate-new-buffer base))))
4143 (switch-to-buffer buffer)
4145 ;; We do it this way to make `normal-mode' set the appropriate mode.
4148 (setq buffer-file-name (expand-file-name base))
4150 (setq buffer-file-name nil))
4151 (goto-char (point-min)))))
4153 (defun gnus-mime-print-part (&optional handle)
4154 "Print the MIME part under point."
4156 (gnus-article-check-buffer)
4157 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4158 (contents (and handle (mm-get-part handle)))
4159 (file (make-temp-name (expand-file-name "mm." mm-tmp-directory)))
4160 (printer (mailcap-mime-info (mm-handle-type handle) "print")))
4165 (with-temp-file file
4167 (call-process shell-file-name nil
4168 (generate-new-buffer " *mm*")
4170 shell-command-switch
4172 printer file (mm-handle-type handle))))
4176 (gnus-print-buffer))))))
4178 (defun gnus-mime-inline-part (&optional handle arg)
4179 "Insert the MIME part under point into the current buffer."
4180 (interactive (list nil current-prefix-arg))
4181 (gnus-article-check-buffer)
4182 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4187 (if (and (not arg) (mm-handle-undisplayer handle))
4188 (mm-remove-part handle)
4189 (setq contents (mm-get-part handle))
4192 (setq charset (or (mail-content-type-get
4193 (mm-handle-type handle) 'charset)
4194 gnus-newsgroup-charset)))
4196 (if (mm-handle-undisplayer handle)
4197 (mm-remove-part handle))
4200 gnus-summary-show-article-charset-alist))
4201 (mm-read-coding-system "Charset: ")))))
4203 (mm-insert-inline handle
4205 (setq charset (mm-charset-to-coding-system
4207 (not (eq charset 'ascii)))
4208 (mm-decode-coding-string contents charset)
4212 (defun gnus-mime-view-part-as-charset (&optional handle arg)
4213 "Insert the MIME part under point into the current buffer using the
4215 (interactive (list nil current-prefix-arg))
4216 (gnus-article-check-buffer)
4217 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4222 (if (mm-handle-undisplayer handle)
4223 (mm-remove-part handle))
4224 (let ((gnus-newsgroup-charset
4226 gnus-summary-show-article-charset-alist))
4227 (mm-read-coding-system "Charset: ")))
4228 (gnus-newsgroup-ignored-charsets 'gnus-all))
4229 (gnus-article-press-button)))))
4231 (defun gnus-mime-externalize-part (&optional handle)
4232 "View the MIME part under point with an external viewer."
4234 (gnus-article-check-buffer)
4235 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4236 (mm-user-display-methods nil)
4237 (mm-inlined-types nil)
4238 (mail-parse-charset gnus-newsgroup-charset)
4239 (mail-parse-ignored-charsets
4240 (save-excursion (set-buffer gnus-summary-buffer)
4241 gnus-newsgroup-ignored-charsets)))
4243 (if (mm-handle-undisplayer handle)
4244 (mm-remove-part handle)
4245 (mm-display-part handle)))))
4247 (defun gnus-mime-internalize-part (&optional handle)
4248 "View the MIME part under point with an internal viewer.
4249 If no internal viewer is available, use an external viewer."
4251 (gnus-article-check-buffer)
4252 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4253 (mm-inlined-types '(".*"))
4254 (mm-inline-large-images t)
4255 (mail-parse-charset gnus-newsgroup-charset)
4256 (mail-parse-ignored-charsets
4257 (save-excursion (set-buffer gnus-summary-buffer)
4258 gnus-newsgroup-ignored-charsets)))
4260 (if (mm-handle-undisplayer handle)
4261 (mm-remove-part handle)
4262 (mm-display-part handle)))))
4264 (defun gnus-mime-action-on-part (&optional action)
4265 "Do something with the MIME attachment at \(point\)."
4267 (list (completing-read "Action: " gnus-mime-action-alist)))
4268 (gnus-article-check-buffer)
4269 (let ((action-pair (assoc action gnus-mime-action-alist)))
4271 (funcall (cdr action-pair)))))
4273 (defun gnus-article-part-wrapper (n function)
4274 (save-current-buffer
4275 (set-buffer gnus-article-buffer)
4276 (when (> n (length gnus-article-mime-handle-alist))
4277 (error "No such part"))
4278 (gnus-article-goto-part n)
4279 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
4280 (funcall function handle))))
4282 (defun gnus-article-pipe-part (n)
4283 "Pipe MIME part N, which is the numerical prefix."
4285 (gnus-article-part-wrapper n 'mm-pipe-part))
4287 (defun gnus-article-save-part (n)
4288 "Save MIME part N, which is the numerical prefix."
4290 (gnus-article-part-wrapper n 'mm-save-part))
4292 (defun gnus-article-interactively-view-part (n)
4293 "View MIME part N interactively, which is the numerical prefix."
4295 (gnus-article-part-wrapper n 'mm-interactively-view-part))
4297 (defun gnus-article-copy-part (n)
4298 "Copy MIME part N, which is the numerical prefix."
4300 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
4302 (defun gnus-article-view-part-as-charset (n)
4303 "Copy MIME part N, which is the numerical prefix."
4305 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-charset))
4307 (defun gnus-article-externalize-part (n)
4308 "View MIME part N externally, which is the numerical prefix."
4310 (gnus-article-part-wrapper n 'gnus-mime-externalize-part))
4312 (defun gnus-article-inline-part (n)
4313 "Inline MIME part N, which is the numerical prefix."
4315 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
4317 (defun gnus-article-mime-match-handle-first (condition)
4319 (let ((alist gnus-article-mime-handle-alist) ihandle n)
4320 (while (setq ihandle (pop alist))
4322 ((functionp condition)
4323 (funcall condition (cdr ihandle)))
4324 ((eq condition 'undisplayed)
4325 (not (or (mm-handle-undisplayer (cdr ihandle))
4326 (equal (mm-handle-media-type (cdr ihandle))
4327 "multipart/alternative"))))
4328 ((eq condition 'undisplayed-alternative)
4329 (not (mm-handle-undisplayer (cdr ihandle))))
4331 (gnus-article-goto-part (car ihandle))
4332 (or (not n) (< (car ihandle) n)))
4333 (setq n (car ihandle))))
4337 (defun gnus-article-view-part (&optional n)
4338 "View MIME part N, which is the numerical prefix."
4340 (save-current-buffer
4341 (set-buffer gnus-article-buffer)
4342 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
4343 gnus-article-mime-match-handle-function)))
4344 (when (> n (length gnus-article-mime-handle-alist))
4345 (error "No such part"))
4346 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
4347 (when (gnus-article-goto-part n)
4348 (if (equal (car handle) "multipart/alternative")
4349 (gnus-article-press-button)
4350 (when (eq (gnus-mm-display-part handle) 'internal)
4351 (gnus-set-window-start)))))))
4353 (defsubst gnus-article-mime-total-parts ()
4354 (if (bufferp (car gnus-article-mime-handles))
4356 (1- (length gnus-article-mime-handles))))
4358 (defun gnus-mm-display-part (handle)
4359 "Display HANDLE and fix MIME button."
4360 (let ((id (get-text-property (point) 'gnus-part))
4365 (let ((window (selected-window))
4366 (mail-parse-charset gnus-newsgroup-charset)
4367 (mail-parse-ignored-charsets
4368 (save-excursion (set-buffer gnus-summary-buffer)
4369 gnus-newsgroup-ignored-charsets)))
4372 (let ((win (gnus-get-buffer-window (current-buffer) t))
4375 (select-window win))
4378 (if (mm-handle-displayed-p handle)
4379 ;; This will remove the part.
4380 (mm-display-part handle)
4382 (narrow-to-region (point)
4383 (if (eobp) (point) (1+ (point))))
4384 (mm-display-part handle)
4385 ;; We narrow to the part itself and
4386 ;; then call the treatment functions.
4387 (goto-char (point-min))
4389 (narrow-to-region (point) (point-max))
4392 (gnus-article-mime-total-parts)
4393 (mm-handle-media-type handle)))))
4394 (if (window-live-p window)
4395 (select-window window)))))
4397 (delete-region (gnus-point-at-bol) (progn (forward-line 1) (point)))
4398 (gnus-insert-mime-button
4399 handle id (list (mm-handle-displayed-p handle)))
4400 (goto-char point))))
4402 (defun gnus-article-goto-part (n)
4403 "Go to MIME part N."
4404 (let ((point (text-property-any (point-min) (point-max) 'gnus-part n)))
4406 (goto-char point))))
4408 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
4409 (let ((gnus-tmp-name
4410 (or (mail-content-type-get (mm-handle-type handle) 'name)
4411 (mail-content-type-get (mm-handle-disposition handle) 'filename)
4412 (mail-content-type-get (mm-handle-type handle) 'url)
4414 (gnus-tmp-type (mm-handle-media-type handle))
4415 (gnus-tmp-description
4416 (mail-decode-encoded-word-string (or (mm-handle-description handle)
4419 (if (if displayed (car displayed)
4420 (mm-handle-displayed-p handle))
4422 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
4424 gnus-tmp-type-long b e)
4425 (when (string-match ".*/" gnus-tmp-name)
4426 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
4427 (setq gnus-tmp-type-long (concat gnus-tmp-type
4428 (and (not (equal gnus-tmp-name ""))
4429 (concat "; " gnus-tmp-name))))
4430 (unless (equal gnus-tmp-description "")
4431 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
4436 gnus-mime-button-line-format gnus-mime-button-line-format-alist
4437 `(,@(gnus-local-map-property gnus-mime-button-map)
4438 gnus-callback gnus-mm-display-part
4439 gnus-part ,gnus-tmp-id
4440 article-type annotation
4443 (widget-convert-button
4446 :action 'gnus-widget-press-button
4447 :button-keymap gnus-mime-button-map
4449 (lambda (widget/window &optional overlay pos)
4450 ;; Needed to properly clear the message due to a bug in
4451 ;; wid-edit (XEmacs only).
4452 (if (boundp 'help-echo-owns-message)
4453 (setq help-echo-owns-message t))
4455 "%S: %s the MIME part; %S: more options"
4456 (aref gnus-mouse-2 0)
4457 ;; XEmacs will get a single widget arg; Emacs 21 will get
4458 ;; window, overlay, position.
4459 (if (mm-handle-displayed-p
4461 (with-current-buffer (gnus-overlay-buffer overlay)
4462 (widget-get (widget-at (gnus-overlay-start overlay))
4464 (widget-get widget/window :mime-handle)))
4466 (aref gnus-down-mouse-3 0))))))
4468 (defun gnus-widget-press-button (elems el)
4469 (goto-char (widget-get elems :from))
4470 (gnus-article-press-button))
4472 (defvar gnus-displaying-mime nil)
4474 (defun gnus-display-mime (&optional ihandles)
4475 "Display the MIME parts."
4477 (save-selected-window
4478 (let ((window (get-buffer-window gnus-article-buffer))
4481 (select-window window)
4482 ;; We have to do this since selecting the window
4483 ;; may change the point. So we set the window point.
4484 (set-window-point window point)))
4485 (let* ((handles (or ihandles (mm-dissect-buffer) (mm-uu-dissect)))
4486 buffer-read-only handle name type b e display)
4487 (when (and (not ihandles)
4488 (not gnus-displaying-mime))
4489 ;; Top-level call; we clean up.
4490 (when gnus-article-mime-handles
4491 (mm-destroy-parts gnus-article-mime-handles)
4492 (setq gnus-article-mime-handle-alist nil));; A trick.
4493 (setq gnus-article-mime-handles handles)
4494 ;; We allow users to glean info from the handles.
4495 (when gnus-article-mime-part-function
4496 (gnus-mime-part-function handles)))
4498 (or (not (stringp (car handles)))
4501 (when (and (not ihandles)
4502 (not gnus-displaying-mime))
4503 ;; Clean up for mime parts.
4505 (delete-region (point) (point-max)))
4506 (let ((gnus-displaying-mime t))
4507 (gnus-mime-display-part handles)))
4510 (narrow-to-region (point) (point-max))
4511 (gnus-treat-article nil 1 1)
4514 ;; Highlight the headers.
4518 (narrow-to-region (point-min) (point))
4519 (gnus-treat-article 'head))))))))
4521 (defvar gnus-mime-display-multipart-as-mixed nil)
4522 (defvar gnus-mime-display-multipart-alternative-as-mixed nil)
4523 (defvar gnus-mime-display-multipart-related-as-mixed nil)
4525 (defun gnus-mime-display-part (handle)
4528 ((not (stringp (car handle)))
4529 (gnus-mime-display-single handle))
4530 ;; User-defined multipart
4531 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
4532 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
4534 ;; multipart/alternative
4535 ((and (equal (car handle) "multipart/alternative")
4536 (not (or gnus-mime-display-multipart-as-mixed
4537 gnus-mime-display-multipart-alternative-as-mixed)))
4538 (let ((id (1+ (length gnus-article-mime-handle-alist))))
4539 (push (cons id handle) gnus-article-mime-handle-alist)
4540 (gnus-mime-display-alternative (cdr handle) nil nil id)))
4541 ;; multipart/related
4542 ((and (equal (car handle) "multipart/related")
4543 (not (or gnus-mime-display-multipart-as-mixed
4544 gnus-mime-display-multipart-related-as-mixed)))
4545 ;;;!!!We should find the start part, but we just default
4546 ;;;!!!to the first part.
4547 ;;(gnus-mime-display-part (cadr handle))
4548 ;;;!!! Most multipart/related is an HTML message plus images.
4549 ;;;!!! Unfortunately we are unable to let W3 display those
4550 ;;;!!! included images, so we just display it as a mixed multipart.
4551 ;;(gnus-mime-display-mixed (cdr handle))
4552 ;;;!!! No, w3 can display everything just fine.
4553 (gnus-mime-display-part (cadr handle)))
4554 ((equal (car handle) "multipart/signed")
4555 (gnus-add-wash-type 'signed)
4556 (gnus-mime-display-security handle))
4557 ((equal (car handle) "multipart/encrypted")
4558 (gnus-add-wash-type 'encrypted)
4559 (gnus-mime-display-security handle))
4560 ;; Other multiparts are handled like multipart/mixed.
4562 (gnus-mime-display-mixed (cdr handle)))))
4564 (defun gnus-mime-part-function (handles)
4565 (if (stringp (car handles))
4566 (mapcar 'gnus-mime-part-function (cdr handles))
4567 (funcall gnus-article-mime-part-function handles)))
4569 (defun gnus-mime-display-mixed (handles)
4570 (mapcar 'gnus-mime-display-part handles))
4572 (defun gnus-mime-display-single (handle)
4573 (let ((type (mm-handle-media-type handle))
4574 (ignored gnus-ignored-mime-types)
4581 (when (string-match (pop ignored) type)
4582 (throw 'ignored nil)))
4583 (if (and (setq not-attachment
4584 (and (not (mm-inline-override-p handle))
4585 (or (not (mm-handle-disposition handle))
4586 (equal (car (mm-handle-disposition handle))
4588 (mm-attachment-override-p handle))))
4589 (mm-automatic-display-p handle)
4591 (mm-inlinable-p handle)
4592 (mm-inlined-p handle))
4593 (mm-automatic-external-display-p type)))
4595 (when (equal (mm-handle-media-supertype handle) "text")
4597 (let ((id (1+ (length gnus-article-mime-handle-alist)))
4599 (push (cons id handle) gnus-article-mime-handle-alist)
4600 (when (or (not display)
4601 (not (gnus-unbuttonized-mime-type-p type)))
4602 ;(gnus-article-insert-newline)
4603 (gnus-insert-mime-button
4604 handle id (list (or display (and not-attachment text))))
4605 (gnus-article-insert-newline)
4606 ;(gnus-article-insert-newline)
4607 ;; Remember modify the number of forward lines.
4615 (let ((mail-parse-charset gnus-newsgroup-charset)
4616 (mail-parse-ignored-charsets
4617 (save-excursion (condition-case ()
4618 (set-buffer gnus-summary-buffer)
4620 gnus-newsgroup-ignored-charsets)))
4621 (mm-display-part handle t))
4622 (goto-char (point-max)))
4623 ((and text not-attachment)
4627 (gnus-article-insert-newline)
4628 (mm-insert-inline handle (mm-get-part handle))
4629 (goto-char (point-max))))
4633 (narrow-to-region beg (point))
4636 (gnus-article-mime-total-parts)
4637 (mm-handle-media-type handle)))))))))
4639 (defun gnus-unbuttonized-mime-type-p (type)
4640 "Say whether TYPE is to be unbuttonized."
4641 (unless gnus-inhibit-mime-unbuttonizing
4643 (let ((types gnus-unbuttonized-mime-types))
4645 (when (string-match (pop types) type)
4646 (throw 'found t)))))
4648 (let ((types gnus-buttonized-mime-types))
4650 (when (string-match (pop types) type)
4651 (throw 'found t)))))))))
4653 (defun gnus-article-insert-newline ()
4654 "Insert a newline, but mark it as undeletable."
4655 (gnus-put-text-property
4656 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
4658 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
4659 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
4662 handle buffer-read-only from props begend not-pref)
4663 (save-window-excursion
4666 (narrow-to-region (car ibegend)
4669 (goto-char (car ibegend))
4672 (delete-region (point-min) (point-max))
4673 (mm-remove-parts handles))
4674 (setq begend (list (point-marker)))
4676 (unless (setq not-pref (cadr (member preferred ihandles)))
4677 (setq not-pref (car ihandles)))
4680 (not (gnus-unbuttonized-mime-type-p
4681 "multipart/alternative")))
4682 (gnus-add-text-properties
4685 (insert (format "%d. " id))
4689 (unless ,(not ibegend)
4690 (setq gnus-article-mime-handle-alist
4691 ',gnus-article-mime-handle-alist))
4692 (gnus-mime-display-alternative
4693 ',ihandles ',not-pref ',begend ,id))
4694 ,@(gnus-local-map-property gnus-mime-button-map)
4695 ,gnus-mouse-face-prop ,gnus-article-mouse-face
4696 face ,gnus-article-button-face
4699 (widget-convert-button 'link from (point)
4700 :action 'gnus-widget-press-button
4701 :button-keymap gnus-widget-button-keymap)
4703 (while (setq handle (pop handles))
4704 (gnus-add-text-properties
4707 (insert (format "(%c) %-18s"
4708 (if (equal handle preferred) ?* ? )
4709 (mm-handle-media-type handle)))
4713 (unless ,(not ibegend)
4714 (setq gnus-article-mime-handle-alist
4715 ',gnus-article-mime-handle-alist))
4716 (gnus-mime-display-alternative
4717 ',ihandles ',handle ',begend ,id))
4718 ,@(gnus-local-map-property gnus-mime-button-map)
4719 ,gnus-mouse-face-prop ,gnus-article-mouse-face
4720 face ,gnus-article-button-face
4723 (widget-convert-button 'link from (point)
4724 :action 'gnus-widget-press-button
4725 :button-keymap gnus-widget-button-keymap)
4729 (if (stringp (car preferred))
4730 (gnus-display-mime preferred)
4731 (let ((mail-parse-charset gnus-newsgroup-charset)
4732 (mail-parse-ignored-charsets
4733 (save-excursion (set-buffer gnus-summary-buffer)
4734 gnus-newsgroup-ignored-charsets)))
4735 (mm-display-part preferred)
4739 (narrow-to-region (car begend) (point-max))
4741 nil (length gnus-article-mime-handle-alist)
4742 (gnus-article-mime-total-parts)
4743 (mm-handle-media-type handle))))))
4744 (goto-char (point-max))
4745 (setcdr begend (point-marker)))))
4747 (goto-char point))))
4749 (defconst gnus-article-wash-status-strings
4750 (let ((alist '((cite "c" "Possible hidden citation text"
4751 " " "All citation text visible")
4752 (headers "h" "Hidden headers"
4753 " " "All headers visible.")
4754 (pgp "p" "Encrypted or signed message status hidden"
4755 " " "No hidden encryption nor digital signature status")
4756 (signature "s" "Signature has been hidden"
4757 " " "Signature is visible")
4758 (overstrike "o" "Overstrike (^H) characters applied"
4759 " " "No overstrike characters applied")
4760 (gnus-show-mime "m" "Mime processing is activated"
4761 " " "Mime processing is not activated")
4762 (emphasis "e" "/*_Emphasis_*/ characters applied"
4763 " " "No /*_emphasis_*/ characters applied")))
4765 (dolist (entry alist result)
4766 (let ((key (nth 0 entry))
4767 (on (copy-sequence (nth 1 entry)))
4768 (on-help (nth 2 entry))
4769 (off (copy-sequence (nth 3 entry)))
4770 (off-help (nth 4 entry)))
4771 (put-text-property 0 1 'help-echo on-help on)
4772 (put-text-property 0 1 'help-echo off-help off)
4773 (push (list key on off) result))))
4774 "Alist of strings describing wash status in the mode line.
4775 Each entry has the form (KEY ON OF), where the KEY is a symbol
4776 representing the particular washing function, ON is the string to use
4777 in the article mode line when the washing function is active, and OFF
4778 is the string to use when it is inactive.")
4780 (defun gnus-article-wash-status-entry (key value)
4781 (let ((entry (assoc key gnus-article-wash-status-strings)))
4782 (if value (nth 1 entry) (nth 2 entry))))
4784 (defun gnus-article-wash-status ()
4785 "Return a string which display status of article washing."
4787 (set-buffer gnus-article-buffer)
4788 (let ((cite (memq 'cite gnus-article-wash-types))
4789 (headers (memq 'headers gnus-article-wash-types))
4790 (boring (memq 'boring-headers gnus-article-wash-types))
4791 (pgp (memq 'pgp gnus-article-wash-types))
4792 (pem (memq 'pem gnus-article-wash-types))
4793 (signed (memq 'signed gnus-article-wash-types))
4794 (encrypted (memq 'encrypted gnus-article-wash-types))
4795 (signature (memq 'signature gnus-article-wash-types))
4796 (overstrike (memq 'overstrike gnus-article-wash-types))
4797 (emphasis (memq 'emphasis gnus-article-wash-types)))
4799 (gnus-article-wash-status-entry 'cite cite)
4800 (gnus-article-wash-status-entry 'headers (or headers boring))
4801 (gnus-article-wash-status-entry 'pgp (or pgp pem signed encrypted))
4802 (gnus-article-wash-status-entry 'signature signature)
4803 (gnus-article-wash-status-entry 'overstrike overstrike)
4804 (gnus-article-wash-status-entry 'gnus-show-mime gnus-show-mime)
4805 (gnus-article-wash-status-entry 'emphasis emphasis)))))
4807 (defun gnus-add-wash-type (type)
4808 "Add a washing of TYPE to the current status."
4809 (add-to-list 'gnus-article-wash-types type))
4811 (defun gnus-delete-wash-type (type)
4812 "Add a washing of TYPE to the current status."
4813 (setq gnus-article-wash-types (delq type gnus-article-wash-types)))
4815 (defun gnus-add-image (category image)
4816 "Add IMAGE of CATEGORY to the list of displayed images."
4817 (let ((entry (assq category gnus-article-image-alist)))
4819 (setq entry (list category))
4820 (push entry gnus-article-image-alist))
4821 (nconc entry (list image))))
4823 (defun gnus-delete-images (category)
4824 "Delete all images in CATEGORY."
4825 (let ((entry (assq category gnus-article-image-alist)))
4826 (dolist (image (cdr entry))
4827 (gnus-remove-image image))
4828 (setq gnus-article-image-alist (delq entry gnus-article-image-alist))
4829 (gnus-delete-wash-type category)))
4831 (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
4833 (defun gnus-article-maybe-hide-headers ()
4834 "Hide unwanted headers if `gnus-have-all-headers' is nil.
4835 Provided for backwards compatibility."
4836 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
4837 (not (save-excursion (set-buffer gnus-summary-buffer)
4838 gnus-have-all-headers)))
4839 (not gnus-inhibit-hiding))
4840 (gnus-article-hide-headers)))
4844 (defun gnus-output-to-file (file-name)
4845 "Append the current article to a file named FILE-NAME."
4846 (let ((artbuf (current-buffer)))
4848 (insert-buffer-substring artbuf)
4849 ;; Append newline at end of the buffer as separator, and then
4851 (goto-char (point-max))
4853 (let ((file-name-coding-system nnmail-pathname-coding-system)
4854 (pathname-coding-system nnmail-pathname-coding-system))
4855 (write-region-as-binary (point-min) (point-max) file-name 'append))
4858 (defun gnus-narrow-to-page (&optional arg)
4859 "Narrow the article buffer to a page.
4860 If given a numerical ARG, move forward ARG pages."
4862 (setq arg (if arg (prefix-numeric-value arg) 0))
4864 (set-buffer gnus-article-buffer)
4865 (goto-char (point-min))
4867 ;; Remove any old next/prev buttons.
4868 (when (gnus-visual-p 'page-marker)
4869 (let ((buffer-read-only nil))
4870 (gnus-remove-text-with-property 'gnus-prev)
4871 (gnus-remove-text-with-property 'gnus-next)))
4874 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
4876 (re-search-forward page-delimiter nil 'move arg)))
4877 (goto-char (match-end 0)))
4880 (if (re-search-forward page-delimiter nil 'move)
4883 (when (and (gnus-visual-p 'page-marker)
4884 (not (= (point-min) 1)))
4886 (goto-char (point-min))
4887 (gnus-insert-prev-page-button)))
4888 (when (and (gnus-visual-p 'page-marker)
4889 (< (+ (point-max) 2) (buffer-size)))
4891 (goto-char (point-max))
4892 (gnus-insert-next-page-button)))))
4894 ;; Article mode commands
4896 (defun gnus-article-goto-next-page ()
4897 "Show the next page of the article."
4899 (when (gnus-article-next-page)
4900 (goto-char (point-min))
4901 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
4903 (defun gnus-article-goto-prev-page ()
4904 "Show the next page of the article."
4906 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
4907 (gnus-article-prev-page nil)))
4909 (defun gnus-article-next-page (&optional lines)
4910 "Show the next page of the current article.
4911 If end of article, return non-nil. Otherwise return nil.
4912 Argument LINES specifies lines to be scrolled up."
4914 (let ((start (window-start))
4915 end-of-buffer end-of-page)
4917 (move-to-window-line -1)
4918 (if (<= (point) start)
4921 (setq start (point)))
4924 (unless (or (cond ((eq (1+ (buffer-size)) (point))
4925 (and (pos-visible-in-window-p)
4926 (setq end-of-buffer t)))
4928 (setq end-of-page t)))
4930 (move-to-window-line lines)
4931 (unless (search-backward "\n\n" nil t)
4932 (setq start (point)))))
4933 (cond (end-of-buffer t)
4935 (gnus-narrow-to-page 1)
4939 (set-window-start (selected-window) start)
4940 (let (window-pixel-scroll-increment)
4944 (defun gnus-article-prev-page (&optional lines)
4945 "Show previous page of current article.
4946 Argument LINES specifies lines to be scrolled down."
4948 (let (beginning-of-buffer beginning-of-page)
4950 (move-to-window-line 0)
4951 (cond ((eq 1 (point))
4952 (setq beginning-of-buffer t))
4954 (setq beginning-of-page t))))
4955 (cond (beginning-of-buffer)
4957 (gnus-narrow-to-page -1))
4960 (let (window-pixel-scroll-increment)
4961 (scroll-down lines))
4962 (beginning-of-buffer
4963 (goto-char (point-min))))))))
4965 (defun gnus-article-refer-article ()
4966 "Read article specified by message-id around point."
4968 (let ((point (point)))
4969 (search-forward ">" nil t) ;Move point to end of "<....>".
4970 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
4971 (let ((message-id (match-string 1)))
4973 (set-buffer gnus-summary-buffer)
4974 (gnus-summary-refer-article message-id))
4976 (error "No references around point"))))
4978 (defun gnus-article-show-summary ()
4979 "Reconfigure windows to show summary buffer."
4981 (if (not (gnus-buffer-live-p gnus-summary-buffer))
4982 (error "There is no summary buffer for this article buffer")
4983 (gnus-article-set-globals)
4984 (gnus-configure-windows 'article)
4985 (gnus-summary-goto-subject gnus-current-article)
4986 (gnus-summary-position-point)))
4988 (defun gnus-article-describe-briefly ()
4989 "Describe article mode commands briefly."
4991 (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")))
4993 (defun gnus-article-summary-command ()
4994 "Execute the last keystroke in the summary buffer."
4996 (let ((obuf (current-buffer))
4997 (owin (current-window-configuration))
4999 (switch-to-buffer gnus-article-current-summary 'norecord)
5000 (setq func (lookup-key (current-local-map) (this-command-keys)))
5001 (call-interactively func)
5003 (set-window-configuration owin)
5004 (set-window-point (get-buffer-window (current-buffer)) (point))))
5006 (defun gnus-article-summary-command-nosave ()
5007 "Execute the last keystroke in the summary buffer."
5010 (pop-to-buffer gnus-article-current-summary 'norecord)
5011 (setq func (lookup-key (current-local-map) (this-command-keys)))
5012 (call-interactively func)))
5014 (defun gnus-article-check-buffer ()
5015 "Beep if not in an article buffer."
5016 (unless (eq (get-buffer gnus-article-buffer) (current-buffer))
5017 (error "Command invoked outside of a Gnus article buffer")))
5019 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
5020 "Read a summary buffer key sequence and execute it from the article buffer."
5022 (gnus-article-check-buffer)
5024 '("q" "Q" "c" "r" "\C-c\C-f" "m" "a" "f"
5025 "Zc" "ZC" "ZE" "ZJ" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
5026 "=" "^" "\M-^" "|"))
5032 '("n" "Gn" "p" "Gp"))
5035 (set-buffer gnus-article-current-summary)
5036 (let (gnus-pick-mode)
5037 (push (or key last-command-event) unread-command-events)
5038 (setq keys (static-if (featurep 'xemacs)
5039 (events-to-keys (read-key-sequence nil))
5040 (read-key-sequence nil)))))
5043 (if (or (member keys nosaves)
5044 (member keys nosave-but-article)
5045 (member keys nosave-in-article))
5047 (save-window-excursion
5048 (pop-to-buffer gnus-article-current-summary 'norecord)
5049 ;; We disable the pick minor mode commands.
5050 (let (gnus-pick-mode)
5051 (setq func (lookup-key (current-local-map) keys))))
5055 (unless (member keys nosave-in-article)
5056 (set-buffer gnus-article-current-summary))
5057 (call-interactively func)
5058 (setq new-sum-point (point)))
5059 (when (member keys nosave-but-article)
5060 (pop-to-buffer gnus-article-buffer 'norecord)))
5061 ;; These commands should restore window configuration.
5062 (let ((obuf (current-buffer))
5063 (owin (current-window-configuration))
5065 (summary gnus-article-current-summary)
5066 func in-buffer selected)
5067 (if not-restore-window
5068 (pop-to-buffer summary 'norecord)
5069 (switch-to-buffer summary 'norecord))
5070 (setq in-buffer (current-buffer))
5071 ;; We disable the pick minor mode commands.
5072 (if (and (setq func (let (gnus-pick-mode)
5073 (lookup-key (current-local-map) keys)))
5076 (call-interactively func)
5077 (setq new-sum-point (point))
5078 (when (eq in-buffer (current-buffer))
5079 (setq selected (gnus-summary-select-article))
5081 (unless not-restore-window
5082 (set-window-configuration owin))
5083 (when (eq selected 'old)
5085 (set-window-start (get-buffer-window (current-buffer))
5087 (set-window-point (get-buffer-window (current-buffer))
5089 (let ((win (get-buffer-window gnus-article-current-summary)))
5091 (set-window-point win new-sum-point)))) )
5092 (switch-to-buffer gnus-article-buffer)
5095 (defun gnus-article-describe-key (key)
5096 "Display documentation of the function invoked by KEY. KEY is a string."
5097 (interactive "kDescribe key: ")
5098 (gnus-article-check-buffer)
5099 (if (eq (key-binding key) 'gnus-article-read-summary-keys)
5101 (set-buffer gnus-article-current-summary)
5102 (let (gnus-pick-mode)
5103 (if (featurep 'xemacs)
5105 (push (elt key 0) unread-command-events)
5106 (setq key (events-to-keys
5107 (read-key-sequence "Describe key: "))))
5108 (setq unread-command-events
5110 (lambda (x) (if (>= x 128) (list 'meta (- x 128)) x))
5112 (setq key (read-key-sequence "Describe key: "))))
5114 (describe-key key)))
5116 (defun gnus-article-describe-key-briefly (key &optional insert)
5117 "Display documentation of the function invoked by KEY. KEY is a string."
5118 (interactive "kDescribe key: \nP")
5119 (gnus-article-check-buffer)
5120 (if (eq (key-binding key) 'gnus-article-read-summary-keys)
5122 (set-buffer gnus-article-current-summary)
5123 (let (gnus-pick-mode)
5124 (if (featurep 'xemacs)
5126 (push (elt key 0) unread-command-events)
5127 (setq key (events-to-keys
5128 (read-key-sequence "Describe key: "))))
5129 (setq unread-command-events
5131 (lambda (x) (if (>= x 128) (list 'meta (- x 128)) x))
5133 (setq key (read-key-sequence "Describe key: "))))
5134 (describe-key-briefly key insert))
5135 (describe-key-briefly key insert)))
5137 (defun gnus-article-reply-with-original (&optional wide)
5138 "Start composing a reply mail to the current message.
5139 The text in the region will be yanked. If the region isn't active,
5140 the entire article will be yanked."
5142 (let ((article (cdr gnus-article-current)) cont)
5144 (gnus-summary-reply (list (list article)) wide)
5145 (setq cont (buffer-substring (point) (mark)))
5146 ;; Deactivate active regions.
5147 (when (and (boundp 'transient-mark-mode)
5148 transient-mark-mode)
5149 (setq mark-active nil))
5151 (list (list article cont)) wide))))
5153 (defun gnus-article-followup-with-original ()
5154 "Compose a followup to the current article.
5155 The text in the region will be yanked. If the region isn't active,
5156 the entire article will be yanked."
5158 (let ((article (cdr gnus-article-current))
5160 (if (not (gnus-region-active-p))
5161 (gnus-summary-followup (list (list article)))
5162 (setq cont (buffer-substring (point) (mark)))
5163 ;; Deactivate active regions.
5164 (when (and (boundp 'transient-mark-mode)
5165 transient-mark-mode)
5166 (setq mark-active nil))
5167 (gnus-summary-followup
5168 (list (list article cont))))))
5170 (defun gnus-article-hide (&optional arg force)
5171 "Hide all the gruft in the current article.
5172 This means that PGP stuff, signatures, cited text and (some)
5173 headers will be hidden.
5174 If given a prefix, show the hidden text instead."
5175 (interactive (append (gnus-article-hidden-arg) (list 'force)))
5176 (gnus-article-hide-headers arg)
5177 (gnus-article-hide-list-identifiers arg)
5178 (gnus-article-hide-pgp arg)
5179 (gnus-article-hide-citation-maybe arg force)
5180 (gnus-article-hide-signature arg))
5182 (defun gnus-article-maybe-highlight ()
5183 "Do some article highlighting if article highlighting is requested."
5184 (when (gnus-visual-p 'article-highlight 'highlight)
5185 (gnus-article-highlight-some)))
5187 (defun gnus-check-group-server ()
5188 ;; Make sure the connection to the server is alive.
5189 (unless (gnus-server-opened
5190 (gnus-find-method-for-group gnus-newsgroup-name))
5191 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
5192 (gnus-request-group gnus-newsgroup-name t)))
5195 (autoload 'nneething-get-file-name "nneething"))
5197 (defun gnus-request-article-this-buffer (article group)
5198 "Get an article and insert it into this buffer.
5199 T-gnus change: Insert an article into `gnus-original-article-buffer'."
5200 (let (do-update-line sparse-header)
5201 ;; The current buffer is `gnus-article-buffer'.
5205 (gnus-kill-all-overlays)
5206 (setq group (or group gnus-newsgroup-name))
5208 ;; Using `gnus-request-article' directly will insert the article into
5209 ;; `nntp-server-buffer' - so we'll save some time by not having to
5210 ;; copy it from the server buffer into the article buffer.
5212 ;; We only request an article by message-id when we do not have the
5213 ;; headers for it, so we'll have to get those.
5214 (when (stringp article)
5215 (gnus-read-header article))
5217 ;; If the article number is negative, that means that this article
5218 ;; doesn't belong in this newsgroup (possibly), so we find its
5219 ;; message-id and request it by id instead of number.
5220 (when (and (numberp article)
5222 (get-buffer gnus-summary-buffer)
5223 (gnus-buffer-exists-p gnus-summary-buffer))
5225 (set-buffer gnus-summary-buffer)
5226 (let ((header (gnus-summary-article-header article)))
5229 ((memq article gnus-newsgroup-sparse)
5230 ;; This is a sparse gap article.
5231 (setq do-update-line article)
5232 (setq article (mail-header-id header))
5233 (setq sparse-header (gnus-read-header article))
5234 (setq gnus-newsgroup-sparse
5235 (delq article gnus-newsgroup-sparse)))
5237 ;; It's a real article.
5238 (setq article (mail-header-id header)))
5240 ;; It is an extracted pseudo-article.
5241 (setq article 'pseudo)
5242 (gnus-request-pseudo-article header))))
5244 (let ((method (gnus-find-method-for-group
5245 gnus-newsgroup-name)))
5246 (when (and (eq (car method) 'nneething)
5248 (let ((dir (nneething-get-file-name
5249 (mail-header-id header))))
5250 (when (and (stringp dir)
5251 (file-directory-p dir))
5252 (setq article 'nneething)
5253 (gnus-group-enter-directory dir))))))))
5254 (setq gnus-original-article (cons group article))
5256 ;; The current buffer is `gnus-original-article-buffer'.
5257 (if (get-buffer gnus-original-article-buffer)
5258 (set-buffer gnus-original-article-buffer)
5259 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
5260 (set-buffer-multibyte nil)
5261 (buffer-disable-undo)
5262 (setq major-mode 'gnus-original-article-mode)
5263 (setq buffer-read-only nil))
5266 ;; Refuse to select canceled articles.
5267 ((and (numberp article)
5269 (get-buffer gnus-summary-buffer)
5270 (gnus-buffer-exists-p gnus-summary-buffer)
5271 (eq (cdr (save-excursion
5272 (set-buffer gnus-summary-buffer)
5273 (assq article gnus-newsgroup-reads)))
5274 gnus-canceled-mark))
5276 ;; Check the backlog.
5277 ((and gnus-keep-backlog
5278 (gnus-backlog-request-article group article (current-buffer)))
5280 ;; Check asynchronous pre-fetch.
5281 ((gnus-async-request-fetched-article group article (current-buffer))
5282 (gnus-async-prefetch-next group article gnus-summary-buffer)
5283 (when (and (numberp article) gnus-keep-backlog)
5284 (gnus-backlog-enter-article group article (current-buffer)))
5287 ((and gnus-use-cache
5289 (gnus-cache-request-article article group))
5291 ;; Check the agent cache.
5292 ((and gnus-agent gnus-agent-cache gnus-plugged
5294 (gnus-agent-request-article article group))
5296 ;; Get the article and put into the article buffer.
5297 ((or (stringp article)
5299 (let ((gnus-override-method gnus-override-method)
5300 (methods (and (stringp article)
5301 gnus-refer-article-method))
5303 (buffer-read-only nil))
5304 (if (or (not (listp methods))
5305 (and (symbolp (car methods))
5306 (assq (car methods) nnoo-definition-alist)))
5307 (setq methods (list methods)))
5308 (when (and (null gnus-override-method)
5310 (setq gnus-override-method (pop methods)))
5312 (when (eq gnus-override-method 'current)
5313 (setq gnus-override-method
5314 (with-current-buffer gnus-summary-buffer
5315 gnus-current-select-method)))
5317 (gnus-kill-all-overlays)
5318 (let ((gnus-newsgroup-name group))
5319 (gnus-check-group-server))
5320 (when (gnus-request-article article group (current-buffer))
5321 (when (numberp article)
5322 (gnus-async-prefetch-next group article
5323 gnus-summary-buffer)
5324 (when gnus-keep-backlog
5325 (gnus-backlog-enter-article
5326 group article (current-buffer))))
5327 (setq result 'article))
5330 (setq gnus-override-method (pop methods))
5331 (setq result 'done))))
5332 (and (eq result 'article) 'article)))
5336 ;; Associate this article with the current summary buffer.
5337 (setq gnus-article-current-summary gnus-summary-buffer)
5339 ;; Copy the requested article from `gnus-original-article-buffer'.
5340 (unless (equal (buffer-name (current-buffer))
5341 (buffer-name (get-buffer gnus-original-article-buffer)))
5342 (insert-buffer gnus-original-article-buffer))
5345 (run-hooks 'gnus-article-decode-hook)
5346 ;; Mark article as decoded or not.
5347 (setq gnus-article-decoded-p gnus-article-decode-hook)
5349 ;; Update sparse articles.
5350 (when (and do-update-line
5351 (or (numberp article)
5353 (let ((buf (current-buffer)))
5354 (set-buffer gnus-summary-buffer)
5355 (gnus-summary-update-article do-update-line sparse-header)
5356 (gnus-summary-goto-subject do-update-line nil t)
5357 (set-window-point (gnus-get-buffer-window (current-buffer) t)
5359 (set-buffer buf))))))
5365 (defcustom gnus-article-edit-mode-hook nil
5366 "Hook run in article edit mode buffers."
5367 :group 'gnus-article-various
5370 (defcustom gnus-article-edit-article-setup-function
5371 'gnus-article-mime-edit-article-setup
5372 "Function called to setup an editing article buffer."
5373 :group 'gnus-article-various
5376 (defvar gnus-article-edit-done-function nil)
5378 (defvar gnus-article-edit-mode-map nil)
5380 ;; Should we be using derived.el for this?
5381 (unless gnus-article-edit-mode-map
5382 (setq gnus-article-edit-mode-map (make-sparse-keymap))
5383 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
5385 (gnus-define-keys gnus-article-edit-mode-map
5386 "\C-c\C-c" gnus-article-edit-done
5387 "\C-c\C-k" gnus-article-edit-exit)
5389 (gnus-define-keys (gnus-article-edit-wash-map
5390 "\C-c\C-w" gnus-article-edit-mode-map)
5391 "f" gnus-article-edit-full-stops))
5393 (define-derived-mode gnus-article-edit-mode text-mode "Article Edit"
5394 "Major mode for editing articles.
5395 This is an extended text-mode.
5397 \\{gnus-article-edit-mode-map}"
5398 (make-local-variable 'gnus-article-edit-done-function)
5399 (make-local-variable 'gnus-prev-winconf)
5400 (set (make-local-variable 'font-lock-defaults)
5401 '(message-font-lock-keywords t))
5402 (setq buffer-read-only nil)
5403 (buffer-enable-undo)
5406 (defun gnus-article-edit (&optional force)
5407 "Edit the current article.
5408 This will have permanent effect only in mail groups.
5409 If FORCE is non-nil, allow editing of articles even in read-only
5412 (when (and (not force)
5413 (gnus-group-read-only-p))
5414 (error "The current newsgroup does not support article editing"))
5415 (gnus-article-date-original)
5416 (gnus-article-edit-article
5418 `(lambda (no-highlight)
5420 (gnus-summary-edit-article-done
5421 ,(or (mail-header-references gnus-current-headers) "")
5422 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
5424 (defun gnus-article-edit-article (start-func exit-func)
5425 "Start editing the contents of the current article buffer."
5426 (let ((winconf (current-window-configuration)))
5427 (set-buffer gnus-article-buffer)
5428 (gnus-article-edit-mode)
5429 (funcall start-func)
5430 (set-buffer-modified-p nil)
5431 (gnus-configure-windows 'edit-article)
5432 (setq gnus-article-edit-done-function exit-func)
5433 (setq gnus-prev-winconf winconf)
5434 (when gnus-article-edit-article-setup-function
5435 (funcall gnus-article-edit-article-setup-function))
5436 (gnus-message 6 "C-c C-c to end edits; C-c C-k to exit")))
5438 (defun gnus-article-edit-done (&optional arg)
5439 "Update the article edits and exit."
5441 (let ((func gnus-article-edit-done-function)
5442 (buf (current-buffer))
5443 (start (window-start)))
5444 (remove-hook 'gnus-article-mode-hook
5445 'gnus-article-mime-edit-article-unwind)
5446 ;; We remove all text props from the article buffer.
5448 (buffer-substring-no-properties (point-min) (point-max)))
5452 (let ((winconf gnus-prev-winconf))
5454 (set-window-configuration winconf)
5455 ;; Tippy-toe some to make sure that point remains where it was.
5456 (save-current-buffer
5458 (set-window-start (get-buffer-window (current-buffer)) start)
5462 (let ((buffer-read-only nil))
5464 ;; The cache and backlog have to be flushed somewhat.
5465 (when gnus-keep-backlog
5466 (gnus-backlog-remove-article
5467 (car gnus-article-current) (cdr gnus-article-current)))
5468 ;; Flush original article as well.
5470 (when (get-buffer gnus-original-article-buffer)
5471 (set-buffer gnus-original-article-buffer)
5472 (setq gnus-original-article nil)))
5473 (when gnus-use-cache
5474 (gnus-cache-update-article
5475 (car gnus-article-current) (cdr gnus-article-current))))
5477 (set-window-start (get-buffer-window buf) start)
5478 (set-window-point (get-buffer-window buf) (point))))
5480 (defun gnus-article-edit-exit ()
5481 "Exit the article editing without updating."
5483 (when (or (not (buffer-modified-p))
5484 (yes-or-no-p "Article modified; kill anyway? "))
5485 (let ((curbuf (current-buffer))
5487 (window-start (window-start)))
5489 (if (gnus-buffer-live-p gnus-original-article-buffer)
5490 (insert-buffer gnus-original-article-buffer))
5491 (let ((winconf gnus-prev-winconf))
5493 (set-window-configuration winconf)
5494 ;; Tippy-toe some to make sure that point remains where it was.
5495 (save-current-buffer
5497 (set-window-start (get-buffer-window (current-buffer)) window-start)
5500 (defun gnus-article-edit-full-stops ()
5501 "Interactively repair spacing at end of sentences."
5504 (goto-char (point-min))
5505 (search-forward-regexp "^$" nil t)
5506 (let ((case-fold-search nil))
5507 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
5510 ;;; Article editing with MIME-Edit
5513 (defcustom gnus-article-mime-edit-article-setup-hook nil
5514 "Hook run after setting up a MIME editing article buffer."
5515 :group 'gnus-article-various
5518 (defun gnus-article-mime-edit-article-unwind ()
5519 "Unwind `gnus-article-buffer' if article editing was given up."
5520 (remove-hook 'gnus-article-mode-hook 'gnus-article-mime-edit-article-unwind)
5521 (when (featurep 'font-lock)
5522 (setq font-lock-defaults nil)
5523 (font-lock-mode -1))
5524 (when mime-edit-mode-flag
5525 (mime-edit-exit 'nomime 'no-error)
5528 (defun gnus-article-mime-edit-article-setup ()
5529 "Convert current buffer to MIME-Edit buffer and turn on MIME-Edit mode
5530 after replacing with the original article."
5531 (setq gnus-show-mime t)
5532 (setq gnus-article-edit-done-function
5533 `(lambda (&rest args)
5534 (when mime-edit-mode-flag
5535 (let (mime-edit-insert-user-agent-field)
5538 (goto-char (point-min))
5539 (let (case-fold-search)
5540 (when (re-search-forward
5541 (format "^%s$" (regexp-quote mail-header-separator))
5543 (replace-match "")))
5544 (apply ,gnus-article-edit-done-function args)
5547 (buffer-substring-no-properties (point-min) (point-max))
5548 (set-buffer (get-buffer-create gnus-original-article-buffer))
5550 (setq gnus-current-headers (gnus-article-make-full-mail-header))
5551 (set-buffer gnus-article-buffer)
5552 (gnus-article-prepare-display)))
5553 (substitute-key-definition 'gnus-article-edit-done
5554 'gnus-article-mime-edit-done
5555 gnus-article-edit-mode-map)
5556 (substitute-key-definition 'gnus-article-edit-exit
5557 'gnus-article-mime-edit-exit
5558 gnus-article-edit-mode-map)
5560 (insert-buffer gnus-original-article-buffer)
5561 (let ((ofn (symbol-function 'mime-edit-decode-single-part-in-buffer)))
5562 (fset 'mime-edit-decode-single-part-in-buffer
5563 (lambda (&rest args)
5564 (if (let ((content-type (car args)))
5565 (and (eq 'message (mime-content-type-primary-type
5567 (eq 'rfc822 (mime-content-type-subtype content-type))))
5568 (setcar (cdr args) 'not-decode-text))
5572 (fset 'mime-edit-decode-single-part-in-buffer ofn)))
5573 (when (featurep 'font-lock)
5574 (set (make-local-variable 'font-lock-defaults)
5575 '(message-font-lock-keywords t))
5576 (font-lock-set-defaults)
5577 (turn-on-font-lock))
5578 (set-buffer-modified-p nil)
5579 (delete-other-windows)
5580 (add-hook 'gnus-article-mode-hook 'gnus-article-mime-edit-article-unwind)
5581 (gnus-run-hooks 'gnus-article-mime-edit-article-setup-hook))
5583 (defun gnus-article-mime-edit-done (&optional arg)
5584 "Update the article MIME edits and exit."
5586 (when (featurep 'font-lock)
5587 (setq font-lock-defaults nil)
5588 (font-lock-mode -1))
5589 (gnus-article-edit-done arg))
5591 (defun gnus-article-mime-edit-exit ()
5592 "Exit the article MIME editing without updating."
5594 (when (or (not (buffer-modified-p))
5595 (yes-or-no-p "Article modified; kill anyway? "))
5596 (when (featurep 'font-lock)
5597 (setq font-lock-defaults nil)
5598 (font-lock-mode -1))
5599 (when mime-edit-mode-flag
5600 (let (mime-edit-insert-user-agent-field)
5603 (goto-char (point-min))
5604 (let (case-fold-search)
5605 (when (re-search-forward
5606 (format "^%s$" (regexp-quote mail-header-separator)) nil t)
5607 (replace-match "")))
5608 (let ((winconf gnus-prev-winconf))
5610 (buffer-substring-no-properties (point-min) (point-max))
5611 (set-buffer (get-buffer-create gnus-original-article-buffer))
5613 (setq gnus-current-headers (gnus-article-make-full-mail-header))
5614 (set-buffer gnus-article-buffer)
5615 (gnus-article-prepare-display)
5616 (set-window-configuration winconf))))
5619 ;;; Article highlights
5622 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
5624 ;;; Internal Variables:
5626 (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\\)\\)"
5627 "Regular expression that matches URLs."
5628 :group 'gnus-article-buttons
5631 (defcustom gnus-button-alist
5632 `(("<\\(url:[>\n\t ]*?\\)?\\(nntp\\|news\\):[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
5633 0 t gnus-button-handle-news 3)
5634 ("\\b\\(nntp\\|news\\):\\([^>\n\t ]*@[^>)!;:,\n\t ]*\\)" 0 t
5635 gnus-button-handle-news 2)
5636 ("\\(\\b<\\(url:[>\n\t ]*\\)?news:[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
5638 gnus-button-fetch-group 4)
5639 ("\\bnews:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
5640 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
5641 t gnus-button-message-id 3)
5642 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 2)
5643 ("mailto:\\([-a-zA-Z.@_+0-9%=?]+\\)" 0 t gnus-url-mailto 1)
5644 ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 1)
5646 ("\\binfo:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t
5647 gnus-button-handle-info 2)
5648 ;; This is how URLs _should_ be embedded in text...
5649 ("<URL: *\\([^<>]*\\)>" 1 t gnus-button-embedded-url 1)
5651 (,gnus-button-url-regexp 0 t browse-url 0))
5652 "*Alist of regexps matching buttons in article bodies.
5654 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
5655 REGEXP: is the string matching text around the button,
5656 BUTTON: is the number of the regexp grouping actually matching the button,
5657 FORM: is a lisp expression which must eval to true for the button to
5659 CALLBACK: is the function to call when the user push this button, and each
5660 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
5662 CALLBACK can also be a variable, in that case the value of that
5663 variable it the real callback function."
5664 :group 'gnus-article-buttons
5665 :type '(repeat (list regexp
5666 (integer :tag "Button")
5668 (function :tag "Callback")
5671 (integer :tag "Regexp group")))))
5673 (defcustom gnus-header-button-alist
5674 `(("^\\(References\\|Message-I[Dd]\\):" "<[^<>]+>"
5675 0 t gnus-button-message-id 0)
5676 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
5677 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
5678 0 t gnus-button-mailto 0)
5679 ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t browse-url 0)
5680 ("^Subject:" ,gnus-button-url-regexp 0 t browse-url 0)
5681 ("^[^:]+:" ,gnus-button-url-regexp 0 t browse-url 0)
5682 ("^[^:]+:" "\\bmailto:\\([-a-zA-Z.@_+0-9%=?]+\\)" 0 t gnus-url-mailto 1)
5683 ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
5684 gnus-button-message-id 3))
5685 "*Alist of headers and regexps to match buttons in article heads.
5687 This alist is very similar to `gnus-button-alist', except that each
5688 alist has an additional HEADER element first in each entry:
5690 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
5692 HEADER is a regexp to match a header. For a fuller explanation, see
5693 `gnus-button-alist'."
5694 :group 'gnus-article-buttons
5695 :group 'gnus-article-headers
5696 :type '(repeat (list (regexp :tag "Header")
5698 (integer :tag "Button")
5700 (function :tag "Callback")
5703 (integer :tag "Regexp group")))))
5705 (defvar gnus-button-regexp nil)
5706 (defvar gnus-button-marker-list nil)
5707 ;; Regexp matching any of the regexps from `gnus-button-alist'.
5709 (defvar gnus-button-last nil)
5710 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
5714 (defun gnus-article-push-button (event)
5715 "Check text under the mouse pointer for a callback function.
5716 If the text under the mouse pointer has a `gnus-callback' property,
5717 call it with the value of the `gnus-data' text property."
5719 (set-buffer (window-buffer (posn-window (event-start event))))
5720 (let* ((pos (posn-point (event-start event)))
5721 (data (get-text-property pos 'gnus-data))
5722 (fun (get-text-property pos 'gnus-callback)))
5725 (funcall fun data))))
5727 (defun gnus-article-press-button ()
5728 "Check text at point for a callback function.
5729 If the text at point has a `gnus-callback' property,
5730 call it with the value of the `gnus-data' text property."
5732 (let* ((data (get-text-property (point) 'gnus-data))
5733 (fun (get-text-property (point) 'gnus-callback)))
5735 (funcall fun data))))
5737 (defun gnus-article-prev-button (n)
5738 "Move point to N buttons backward.
5739 If N is negative, move forward instead."
5741 (gnus-article-next-button (- n)))
5743 (defun gnus-article-next-button (n)
5744 "Move point to N buttons forward.
5745 If N is negative, move backward instead."
5747 (let ((function (if (< n 0) 'previous-single-property-change
5748 'next-single-property-change))
5749 (inhibit-point-motion-hooks t)
5751 (limit (if (< n 0) (point-min) (point-max))))
5753 (while (and (not (= limit (point)))
5755 ;; Skip past the current button.
5756 (when (get-text-property (point) 'gnus-callback)
5757 (goto-char (funcall function (point) 'gnus-callback nil limit)))
5758 ;; Go to the next (or previous) button.
5759 (gnus-goto-char (funcall function (point) 'gnus-callback nil limit))
5760 ;; Put point at the start of the button.
5761 (when (and backward (not (get-text-property (point) 'gnus-callback)))
5762 (goto-char (funcall function (point) 'gnus-callback nil limit)))
5763 ;; Skip past intangible buttons.
5764 (when (get-text-property (point) 'intangible)
5768 (gnus-message 5 "No more buttons"))
5771 (defun gnus-article-highlight (&optional force)
5772 "Highlight current article.
5773 This function calls `gnus-article-highlight-headers',
5774 `gnus-article-highlight-citation',
5775 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
5776 do the highlighting. See the documentation for those functions."
5777 (interactive (list 'force))
5778 (gnus-article-highlight-headers)
5779 (gnus-article-highlight-citation force)
5780 (gnus-article-highlight-signature)
5781 (gnus-article-add-buttons force)
5782 (gnus-article-add-buttons-to-head))
5784 (defun gnus-article-highlight-some (&optional force)
5785 "Highlight current article.
5786 This function calls `gnus-article-highlight-headers',
5787 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
5788 do the highlighting. See the documentation for those functions."
5789 (interactive (list 'force))
5790 (gnus-article-highlight-headers)
5791 (gnus-article-highlight-signature)
5792 (gnus-article-add-buttons))
5794 (defun gnus-article-highlight-headers ()
5795 "Highlight article headers as specified by `gnus-header-face-alist'."
5798 (set-buffer gnus-article-buffer)
5800 (let ((alist gnus-header-face-alist)
5801 (buffer-read-only nil)
5802 (case-fold-search t)
5803 (inhibit-point-motion-hooks t)
5804 entry regexp header-face field-face from hpoints fpoints)
5805 (article-narrow-to-head)
5806 (while (setq entry (pop alist))
5807 (goto-char (point-min))
5808 (setq regexp (concat "^\\("
5809 (if (string-equal "" (nth 0 entry))
5813 header-face (nth 1 entry)
5814 field-face (nth 2 entry))
5815 (while (and (re-search-forward regexp nil t)
5819 (unless (search-forward ":" nil t)
5821 (when (and header-face
5822 (not (memq (point) hpoints)))
5823 (push (point) hpoints)
5824 (gnus-put-text-property from (point) 'face header-face))
5825 (when (and field-face
5826 (not (memq (setq from (point)) fpoints)))
5828 (if (re-search-forward "^[^ \t]" nil t)
5830 (goto-char (point-max)))
5831 (gnus-put-text-property from (point) 'face field-face))))))))
5833 (defun gnus-article-highlight-signature ()
5834 "Highlight the signature in an article.
5835 It does this by highlighting everything after
5836 `gnus-signature-separator' using `gnus-signature-face'."
5838 (when gnus-signature-face
5840 (set-buffer gnus-article-buffer)
5841 (let ((buffer-read-only nil)
5842 (inhibit-point-motion-hooks t))
5844 (when (gnus-article-narrow-to-signature)
5845 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
5846 'face gnus-signature-face)))))))
5848 (defun gnus-article-buttonize-signature ()
5849 "Add button to the signature."
5852 (set-buffer gnus-article-buffer)
5853 (let ((buffer-read-only nil)
5854 (inhibit-point-motion-hooks t))
5855 (when (gnus-article-search-signature)
5856 (gnus-article-add-button (match-beginning 0) (match-end 0)
5857 'gnus-signature-toggle
5858 (set-marker (make-marker)
5859 (1+ (match-end 0))))))))
5861 (defun gnus-button-in-region-p (b e prop)
5862 "Say whether PROP exists in the region."
5863 (text-property-not-all b e prop nil))
5865 (defun gnus-article-add-buttons (&optional force)
5866 "Find external references in the article and make buttons of them.
5867 \"External references\" are things like Message-IDs and URLs, as
5868 specified by `gnus-button-alist'."
5869 (interactive (list 'force))
5871 (set-buffer gnus-article-buffer)
5872 (let ((buffer-read-only nil)
5873 (inhibit-point-motion-hooks t)
5874 (case-fold-search t)
5875 (alist gnus-button-alist)
5877 ;; Remove all old markers.
5878 (let (marker entry new-list)
5879 (while (setq marker (pop gnus-button-marker-list))
5880 (if (or (< marker (point-min)) (>= marker (point-max)))
5881 (push marker new-list)
5883 (when (setq entry (gnus-button-entry))
5884 (put-text-property (match-beginning (nth 1 entry))
5885 (match-end (nth 1 entry))
5886 'gnus-callback nil))
5887 (set-marker marker nil)))
5888 (setq gnus-button-marker-list new-list))
5889 ;; We skip the headers.
5892 (while (setq entry (pop alist))
5893 (setq regexp (car entry))
5895 (while (re-search-forward regexp nil t)
5896 (let* ((start (and entry (match-beginning (nth 1 entry))))
5897 (end (and entry (match-end (nth 1 entry))))
5898 (from (match-beginning 0)))
5899 (when (and (or (eq t (nth 2 entry))
5900 (eval (nth 2 entry)))
5901 (not (gnus-button-in-region-p
5902 start end 'gnus-callback)))
5903 ;; That optional form returned non-nil, so we add the
5905 (gnus-article-add-button
5906 start end 'gnus-button-push
5907 (car (push (set-marker (make-marker) from)
5908 gnus-button-marker-list))))))))))
5910 ;; Add buttons to the head of an article.
5911 (defun gnus-article-add-buttons-to-head ()
5912 "Add buttons to the head of the article."
5915 (set-buffer gnus-article-buffer)
5917 (let ((buffer-read-only nil)
5918 (inhibit-point-motion-hooks t)
5919 (case-fold-search t)
5920 (alist gnus-header-button-alist)
5922 (article-narrow-to-head)
5924 ;; Each alist entry.
5925 (setq entry (car alist)
5927 (goto-char (point-min))
5928 (while (re-search-forward (car entry) nil t)
5929 ;; Each header matching the entry.
5930 (setq beg (match-beginning 0))
5931 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
5932 (match-beginning 0))
5935 (while (re-search-forward (nth 1 entry) end t)
5936 ;; Each match within a header.
5937 (let* ((entry (cdr entry))
5938 (start (match-beginning (nth 1 entry)))
5939 (end (match-end (nth 1 entry)))
5940 (form (nth 2 entry)))
5941 (goto-char (match-end 0))
5943 (gnus-article-add-button
5944 start end (nth 3 entry)
5945 (buffer-substring (match-beginning (nth 4 entry))
5946 (match-end (nth 4 entry)))))))
5947 (goto-char end)))))))
5949 ;;; External functions:
5951 (defun gnus-article-add-button (from to fun &optional data)
5952 "Create a button between FROM and TO with callback FUN and data DATA."
5953 (when gnus-article-button-face
5954 (gnus-overlay-put (gnus-make-overlay from to)
5955 'face gnus-article-button-face))
5956 (gnus-add-text-properties
5958 (nconc (and gnus-article-mouse-face
5959 (list gnus-mouse-face-prop gnus-article-mouse-face))
5960 (list 'gnus-callback fun)
5961 (and data (list 'gnus-data data))))
5962 (widget-convert-button 'link from to :action 'gnus-widget-press-button
5963 ;; Quote `:button-keymap' for Mule 2.3
5964 ;; but it won't work.
5965 ':button-keymap gnus-widget-button-keymap))
5967 ;;; Internal functions:
5969 (defun gnus-article-set-globals ()
5971 (set-buffer gnus-summary-buffer)
5972 (gnus-set-global-variables)))
5974 (defun gnus-signature-toggle (end)
5976 (set-buffer gnus-article-buffer)
5977 (let ((buffer-read-only nil)
5978 (inhibit-point-motion-hooks t)
5979 (limit (next-single-property-change end 'mime-view-entity
5981 (if (text-property-any end limit 'article-type 'signature)
5983 (gnus-delete-wash-type 'signature)
5984 (gnus-remove-text-properties-when
5985 'article-type 'signature end limit
5986 (cons 'article-type (cons 'signature
5987 gnus-hidden-properties))))
5988 (gnus-add-wash-type 'signature)
5989 (gnus-add-text-properties-when
5990 'article-type nil end limit
5991 (cons 'article-type (cons 'signature
5992 gnus-hidden-properties)))))
5993 (let ((gnus-article-mime-handle-alist-1 gnus-article-mime-handle-alist))
5994 (gnus-set-mode-line 'article))))
5996 (defun gnus-button-entry ()
5997 ;; Return the first entry in `gnus-button-alist' matching this place.
5998 (let ((alist gnus-button-alist)
6001 (setq entry (pop alist))
6002 (if (looking-at (car entry))
6007 (defun gnus-button-push (marker)
6008 ;; Push button starting at MARKER.
6011 (let* ((entry (gnus-button-entry))
6012 (inhibit-point-motion-hooks t)
6014 (args (mapcar (lambda (group)
6015 (let ((string (match-string group)))
6016 (gnus-set-text-properties
6017 0 (length string) nil string)
6024 (fboundp (symbol-value fun)))
6025 (apply (symbol-value fun) args))
6027 (gnus-message 1 "You must define `%S' to use this button"
6028 (cons fun args)))))))
6030 (defun gnus-parse-news-url (url)
6031 (let (scheme server group message-id articles)
6034 (goto-char (point-min))
6035 (when (looking-at "\\([A-Za-z]+\\):")
6036 (setq scheme (match-string 1))
6037 (goto-char (match-end 0)))
6038 (when (looking-at "//\\([^/]+\\)/")
6039 (setq server (match-string 1))
6040 (goto-char (match-end 0)))
6043 ((looking-at "\\(.*@.*\\)")
6044 (setq message-id (match-string 1)))
6045 ((looking-at "\\([^/]+\\)/\\([-0-9]+\\)")
6046 (setq group (match-string 1)
6047 articles (split-string (match-string 2) "-")))
6048 ((looking-at "\\([^/]+\\)/?")
6049 (setq group (match-string 1)))
6051 (error "Unknown news URL syntax"))))
6052 (list scheme server group message-id articles)))
6054 (defun gnus-button-handle-news (url)
6056 (destructuring-bind (scheme server group message-id articles)
6057 (gnus-parse-news-url url)
6061 (set-buffer gnus-summary-buffer)
6063 (let ((gnus-refer-article-method (list (list 'nntp server))))
6064 (gnus-summary-refer-article message-id))
6065 (gnus-summary-refer-article message-id))))
6067 (gnus-button-fetch-group url)))))
6069 (defun gnus-button-handle-info (url)
6070 "Fetch an info URL."
6072 "^\\([^:/]+\\)?/\\(.*\\)"
6074 (gnus-info-find-node
6075 (concat "(" (or (gnus-url-unhex-string (match-string 1 url))
6078 (gnus-url-unhex-string (match-string 2 url))))
6079 (error "Can't parse %s" url)))
6081 (defun gnus-button-message-id (message-id)
6084 (set-buffer gnus-summary-buffer)
6085 (gnus-summary-refer-article message-id)))
6087 (defun gnus-button-fetch-group (address)
6088 "Fetch GROUP specified by ADDRESS."
6089 (if (not (string-match "[:/]" address))
6090 ;; This is just a simple group url.
6091 (gnus-group-read-ephemeral-group address gnus-select-method)
6094 "^\\([^:/]+\\)\\(:\\([^/]+\\)\\)?/\\([^/]+\\)\\(/\\([0-9]+\\)\\)?"
6096 (error "Can't parse %s" address)
6097 (gnus-group-read-ephemeral-group
6098 (match-string 4 address)
6099 `(nntp ,(match-string 1 address)
6100 (nntp-address ,(match-string 1 address))
6101 (nntp-port-number ,(if (match-end 3)
6102 (match-string 3 address)
6105 (and (match-end 6) (list (string-to-int (match-string 6 address))))))))
6107 (defun gnus-url-parse-query-string (query &optional downcase)
6108 (let (retval pairs cur key val)
6109 (setq pairs (split-string query "&"))
6111 (setq cur (car pairs)
6113 (if (not (string-match "=" cur))
6115 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
6116 val (gnus-url-unhex-string (substring cur (match-end 0) nil) t))
6118 (setq key (downcase key)))
6119 (setq cur (assoc key retval))
6121 (setcdr cur (cons val (cdr cur)))
6122 (setq retval (cons (list key val) retval)))))
6125 (defun gnus-url-mailto (url)
6126 ;; Send mail to someone
6127 (when (string-match "mailto:/*\\(.*\\)" url)
6128 (setq url (substring url (match-beginning 1) nil)))
6129 (let (to args subject func)
6130 (if (string-match (regexp-quote "?") url)
6131 (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
6132 args (gnus-url-parse-query-string
6133 (substring url (match-end 0) nil) t))
6134 (setq to (gnus-url-unhex-string url)))
6135 (setq args (cons (list "to" to) args)
6136 subject (cdr-safe (assoc "subject" args)))
6139 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
6142 (message-position-on-field (caar args)))
6143 (insert (mapconcat 'identity (cdar args) ", "))
6144 (setq args (cdr args)))
6147 (message-goto-subject))))
6149 (defun gnus-button-embedded-url (address)
6150 "Activate ADDRESS with `browse-url'."
6151 (browse-url (gnus-strip-whitespace address)))
6153 ;;; Next/prev buttons in the article buffer.
6155 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
6156 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
6158 (defvar gnus-prev-page-map
6159 (let ((map (make-sparse-keymap)))
6160 (unless (>= emacs-major-version 21)
6161 ;; XEmacs doesn't care.
6162 (set-keymap-parent map gnus-article-mode-map))
6163 (define-key map gnus-mouse-2 'gnus-button-prev-page)
6164 (define-key map "\r" 'gnus-button-prev-page)
6167 (defun gnus-insert-prev-page-button ()
6169 (buffer-read-only nil)
6170 (situation (get-text-property (point-min) 'mime-view-situation)))
6172 gnus-prev-page-line-format nil
6173 `(,@(gnus-local-map-property gnus-prev-page-map)
6175 gnus-callback gnus-article-button-prev-page
6176 article-type annotation
6177 mime-view-situation ,situation))
6178 (widget-convert-button
6180 :action 'gnus-button-prev-page
6181 :button-keymap gnus-prev-page-map)))
6183 (defvar gnus-next-page-map
6184 (let ((map (make-sparse-keymap)))
6185 (unless (>= emacs-major-version 21)
6186 ;; XEmacs doesn't care.
6187 (set-keymap-parent map gnus-article-mode-map))
6188 (define-key map gnus-mouse-2 'gnus-button-next-page)
6189 (define-key map "\r" 'gnus-button-next-page)
6192 (defun gnus-button-next-page (&optional args more-args)
6193 "Go to the next page."
6195 (let ((win (selected-window)))
6196 (select-window (gnus-get-buffer-window gnus-article-buffer t))
6197 (gnus-article-next-page)
6198 (select-window win)))
6200 (defun gnus-button-prev-page (&optional args more-args)
6201 "Go to the prev page."
6203 (let ((win (selected-window)))
6204 (select-window (gnus-get-buffer-window gnus-article-buffer t))
6205 (gnus-article-prev-page)
6206 (select-window win)))
6208 (defun gnus-insert-next-page-button ()
6210 (buffer-read-only nil)
6211 (situation (get-text-property (point-min) 'mime-view-situation)))
6212 (gnus-eval-format gnus-next-page-line-format nil
6213 `(,@(gnus-local-map-property gnus-next-page-map)
6215 gnus-callback gnus-article-button-next-page
6216 article-type annotation
6217 mime-view-situation ,situation))
6218 (widget-convert-button
6220 :action 'gnus-button-next-page
6221 :button-keymap gnus-next-page-map)))
6223 (defun gnus-article-button-next-page (arg)
6224 "Go to the next page."
6226 (let ((win (selected-window)))
6227 (select-window (gnus-get-buffer-window gnus-article-buffer t))
6228 (gnus-article-next-page)
6229 (select-window win)))
6231 (defun gnus-article-button-prev-page (arg)
6232 "Go to the prev page."
6234 (let ((win (selected-window)))
6235 (select-window (gnus-get-buffer-window gnus-article-buffer t))
6236 (gnus-article-prev-page)
6237 (select-window win)))
6239 (defvar gnus-decode-header-methods
6240 '(mail-decode-encoded-word-region)
6241 "List of methods used to decode headers.
6243 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
6244 is FUNCTION, FUNCTION will be apply to all newsgroups. If item is a
6245 \(REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
6246 whose names match REGEXP.
6249 \((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
6250 mail-decode-encoded-word-region
6251 (\"chinese\" . rfc1843-decode-region))
6254 (defvar gnus-decode-header-methods-cache nil)
6256 (defun gnus-multi-decode-header (start end)
6257 "Apply the functions from `gnus-encoded-word-methods' that match."
6258 (unless (and gnus-decode-header-methods-cache
6259 (eq gnus-newsgroup-name
6260 (car gnus-decode-header-methods-cache)))
6261 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
6264 (nconc gnus-decode-header-methods-cache (list x))
6265 (if (and gnus-newsgroup-name
6266 (string-match (car x) gnus-newsgroup-name))
6267 (nconc gnus-decode-header-methods-cache
6269 gnus-decode-header-methods))
6270 (let ((xlist gnus-decode-header-methods-cache))
6273 (narrow-to-region start end)
6275 (funcall (pop xlist) (point-min) (point-max))))))
6278 ;;; Treatment top-level handling.
6281 (defun gnus-treat-article (condition &optional part-number total-parts type)
6282 (let ((length (- (point-max) (point-min)))
6283 (alist gnus-treatment-function-alist)
6284 (article-goto-body-goes-to-point-min-p t)
6288 (let ((list gnus-article-treat-types))
6290 (when (string-match (pop list) type)
6291 (throw 'found t)))))))
6292 (highlightp (gnus-visual-p 'article-highlight 'highlight))
6293 (entity (static-unless (featurep 'xemacs)
6294 (when (eq 'head condition)
6295 (get-text-property (point-min) 'mime-view-entity))))
6296 val elem buttonized)
6297 (gnus-run-hooks 'gnus-part-display-hook)
6298 (unless gnus-inhibit-treatment
6299 (while (setq elem (pop alist))
6302 (if (gnus-buffer-live-p gnus-summary-buffer)
6303 (set-buffer gnus-summary-buffer))
6304 (symbol-value (car elem))))
6305 (when (and (or (consp val)
6307 (gnus-treat-predicate val)
6308 (or (not (get (car elem) 'highlight))
6310 (when (and (not buttonized)
6312 '(gnus-treat-hide-signature
6313 gnus-treat-highlight-signature)))
6314 (gnus-article-buttonize-signature)
6315 (setq buttonized t))
6317 (funcall (cadr elem)))))
6318 ;; FSF Emacsen does not inherit the existing text properties
6319 ;; in the new text, so we should do it for `mime-view-entity'.
6320 (static-unless (featurep 'xemacs)
6322 (put-text-property (point-min) (point-max)
6323 'mime-view-entity entity))))))
6325 ;; Dynamic variables.
6327 (defvar part-number)
6328 (defvar total-parts)
6333 (defun gnus-treat-predicate (val)
6338 (stringp (car val)))
6339 (apply 'gnus-or (mapcar `(lambda (s)
6340 (string-match s ,(or gnus-newsgroup-name "")))
6343 (let ((pred (pop val)))
6346 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
6348 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
6350 (not (gnus-treat-predicate (car val))))
6352 (equal (car val) type))
6354 (error "%S is not a valid predicate" pred)))))
6364 (eq part-number total-parts))
6368 (error "%S is not a valid value" val))))
6370 (defun gnus-article-encrypt-body (protocol &optional n)
6371 "Encrypt the article body."
6374 (or gnus-article-encrypt-protocol
6375 (completing-read "Encrypt protocol: "
6376 gnus-article-encrypt-protocol-alist
6378 current-prefix-arg))
6379 (let ((func (cdr (assoc protocol gnus-article-encrypt-protocol-alist))))
6381 (error (format "Can't find the encrypt protocol %s" protocol)))
6382 (if (equal gnus-newsgroup-name "nndraft:drafts")
6383 (error "Can't encrypt the article in group nndraft:drafts"))
6384 (if (equal gnus-newsgroup-name "nndraft:queue")
6385 (error "Don't encrypt the article in group nndraft:queue"))
6386 (gnus-summary-iterate n
6388 (set-buffer gnus-summary-buffer)
6389 (let ((mail-parse-charset gnus-newsgroup-charset)
6390 (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
6391 (summary-buffer gnus-summary-buffer)
6393 (gnus-set-global-variables)
6394 (when (gnus-group-read-only-p)
6395 (error "The current newsgroup does not support article encrypt"))
6396 (gnus-summary-show-article t)
6398 (or (mail-header-references gnus-current-headers) ""))
6399 (set-buffer gnus-article-buffer)
6400 (let* ((buffer-read-only nil)
6402 (mapcar (lambda (field)
6403 (and (save-restriction
6404 (message-narrow-to-head)
6405 (goto-char (point-min))
6406 (search-forward field nil t))
6408 (message-narrow-to-field)
6409 (buffer-substring (point-min) (point-max))
6410 (delete-region (point-min) (point-max))
6412 '("Content-Type:" "Content-Transfer-Encoding:"
6413 "Content-Disposition:"))))
6414 (message-narrow-to-head)
6415 (message-remove-header "MIME-Version")
6416 (goto-char (point-max))
6417 (setq point (point))
6418 (insert (apply 'concat headers))
6420 (narrow-to-region point (point-max))
6421 (let ((message-options message-options))
6422 (message-options-set 'message-sender user-mail-address)
6423 (message-options-set 'message-recipients user-mail-address)
6424 (message-options-set 'message-sign-encrypt 'not)
6426 (goto-char (point-min))
6427 (insert "MIME-Version: 1.0\n")
6429 (gnus-summary-edit-article-done
6430 references nil summary-buffer t))
6431 (when gnus-keep-backlog
6432 (gnus-backlog-remove-article
6433 (car gnus-article-current) (cdr gnus-article-current)))
6435 (when (get-buffer gnus-original-article-buffer)
6436 (set-buffer gnus-original-article-buffer)
6437 (setq gnus-original-article nil)))
6438 (when gnus-use-cache
6439 (gnus-cache-update-article
6440 (car gnus-article-current) (cdr gnus-article-current))))))))
6442 (defvar gnus-mime-security-button-line-format "%{%([[%t:%i]%D]%)%}\n"
6443 "The following specs can be used:
6444 %t The security MIME type
6447 %D Details if button is pressed")
6449 (defvar gnus-mime-security-button-end-line-format "%{%([[End of %t]%D]%)%}\n"
6450 "The following specs can be used:
6451 %t The security MIME type
6454 %D Details if button is pressed")
6456 (defvar gnus-mime-security-button-line-format-alist
6457 '((?t gnus-tmp-type ?s)
6458 (?i gnus-tmp-info ?s)
6459 (?d gnus-tmp-details ?s)
6460 (?D gnus-tmp-pressed-details ?s)))
6462 (defvar gnus-mime-security-button-map
6463 (let ((map (make-sparse-keymap)))
6464 (unless (>= (string-to-number emacs-version) 21)
6465 (set-keymap-parent map gnus-article-mode-map))
6466 (define-key map gnus-mouse-2 'gnus-article-push-button)
6467 (define-key map "\r" 'gnus-article-press-button)
6470 (defvar gnus-mime-security-details-buffer nil)
6472 (defvar gnus-mime-security-button-pressed nil)
6474 (defvar gnus-mime-security-show-details-inline t
6475 "If non-nil, show details in the article buffer.")
6477 (defun gnus-mime-security-verify-or-decrypt (handle)
6478 (mm-remove-parts (cdr handle))
6479 (let ((region (mm-handle-multipart-ctl-parameter handle 'gnus-region))
6480 point buffer-read-only)
6482 (goto-char (car region)))
6484 (narrow-to-region (point) (point))
6485 (with-current-buffer (mm-handle-multipart-original-buffer handle)
6486 (let* ((mm-verify-option 'known)
6487 (mm-decrypt-option 'known)
6488 (nparts (mm-possibly-verify-or-decrypt (cdr handle) handle)))
6489 (unless (eq nparts (cdr handle))
6490 (mm-destroy-parts (cdr handle))
6491 (setcdr handle nparts))))
6492 (setq point (point))
6493 (gnus-mime-display-security handle)
6494 (goto-char (point-max)))
6496 (delete-region (point) (cdr region))
6497 (set-marker (car region) nil)
6498 (set-marker (cdr region) nil))
6501 (defun gnus-mime-security-show-details (handle)
6502 (let ((details (mm-handle-multipart-ctl-parameter handle 'gnus-details)))
6504 (if gnus-mime-security-show-details-inline
6505 (let ((gnus-mime-security-button-pressed t)
6506 (gnus-mime-security-button-line-format
6507 (get-text-property (point) 'gnus-line-format))
6510 (while (eq (get-text-property (point) 'gnus-line-format)
6511 gnus-mime-security-button-line-format)
6515 (narrow-to-region (point) (point))
6516 (gnus-insert-mime-security-button handle))
6517 (delete-region (point)
6518 (or (text-property-not-all
6521 gnus-mime-security-button-line-format)
6523 (if (gnus-buffer-live-p gnus-mime-security-details-buffer)
6524 (with-current-buffer gnus-mime-security-details-buffer
6527 (setq gnus-mime-security-details-buffer
6528 (gnus-get-buffer-create "*MIME Security Details*")))
6529 (with-current-buffer gnus-mime-security-details-buffer
6531 (goto-char (point-min)))
6532 (pop-to-buffer gnus-mime-security-details-buffer))
6533 (gnus-message 5 "No details."))))
6535 (defun gnus-mime-security-press-button (handle)
6536 (if (mm-handle-multipart-ctl-parameter handle 'gnus-info)
6537 (gnus-mime-security-show-details handle)
6538 (gnus-mime-security-verify-or-decrypt handle)))
6540 (defun gnus-insert-mime-security-button (handle &optional displayed)
6541 (let* ((protocol (mm-handle-multipart-ctl-parameter handle 'protocol))
6544 (or (nth 2 (assoc protocol mm-verify-function-alist))
6545 (nth 2 (assoc protocol mm-decrypt-function-alist))
6547 (if (equal (car handle) "multipart/signed")
6548 " Signed" " Encrypted")
6551 (or (mm-handle-multipart-ctl-parameter handle 'gnus-info)
6554 (mm-handle-multipart-ctl-parameter handle 'gnus-details))
6555 gnus-tmp-pressed-details
6557 (setq gnus-tmp-details
6558 (if gnus-tmp-details
6559 (concat "\n" gnus-tmp-details) ""))
6560 (setq gnus-tmp-pressed-details
6561 (if gnus-mime-security-button-pressed gnus-tmp-details ""))
6566 gnus-mime-security-button-line-format
6567 gnus-mime-security-button-line-format-alist
6568 `(,@(gnus-local-map-property gnus-mime-security-button-map)
6569 gnus-callback gnus-mime-security-press-button
6570 gnus-line-format ,gnus-mime-security-button-line-format
6571 article-type annotation
6574 (widget-convert-button
6577 :action 'gnus-widget-press-button
6578 :button-keymap gnus-mime-security-button-map
6580 (lambda (widget/window &optional overlay pos)
6581 ;; Needed to properly clear the message due to a bug in
6582 ;; wid-edit (XEmacs only).
6583 (if (boundp 'help-echo-owns-message)
6584 (setq help-echo-owns-message t))
6587 (aref gnus-mouse-2 0))))))
6589 (defun gnus-mime-display-security (handle)
6591 (narrow-to-region (point) (point))
6592 (unless (gnus-unbuttonized-mime-type-p (car handle))
6593 (gnus-insert-mime-security-button handle))
6594 (gnus-mime-display-mixed (cdr handle))
6597 (unless (gnus-unbuttonized-mime-type-p (car handle))
6598 (let ((gnus-mime-security-button-line-format
6599 gnus-mime-security-button-end-line-format))
6600 (gnus-insert-mime-security-button handle)))
6601 (mm-set-handle-multipart-parameter
6603 (cons (set-marker (make-marker) (point-min))
6604 (set-marker (make-marker) (point-max))))))
6610 (defun gnus-article-header-presentation-method (entity situation)
6611 (mime-insert-header entity)
6612 (article-decode-group-name))
6614 (set-alist 'mime-header-presentation-method-alist
6615 'gnus-original-article-mode
6616 #'gnus-article-header-presentation-method)
6618 (defun gnus-mime-preview-quitting-method ()
6619 (mime-preview-kill-buffer)
6620 (delete-other-windows)
6621 (gnus-article-show-summary)
6622 (gnus-summary-select-article gnus-show-all-headers t))
6624 (set-alist 'mime-preview-quitting-method-alist
6625 'gnus-original-article-mode #'gnus-mime-preview-quitting-method)
6627 (set-alist 'mime-preview-following-method-alist
6628 'gnus-original-article-mode #'gnus-following-method)
6630 (set-alist 'mime-preview-over-to-previous-method-alist
6631 'gnus-original-article-mode
6633 (if (> (point-min) 1)
6634 (gnus-article-prev-page)
6635 (gnus-article-read-summary-keys
6636 nil (gnus-character-to-event ?P)))))
6638 (set-alist 'mime-preview-over-to-next-method-alist
6639 'gnus-original-article-mode'
6641 (if (< (point-max) (buffer-size))
6642 (gnus-article-next-page)
6643 (gnus-article-read-summary-keys
6644 nil (gnus-character-to-event ?N)))))
6654 (run-hooks 'gnus-art-load-hook)
6656 ;;; gnus-art.el ends here