1 ;;; gnus-art.el --- article mode commands for Gnus
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001
3 ;; Free Software Foundation, Inc.
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
29 (eval-when-compile (require 'cl))
43 (autoload 'gnus-msg-mail "gnus-msg" nil t)
44 (autoload 'gnus-button-mailto "gnus-msg")
45 (autoload 'gnus-button-reply "gnus-msg" nil t)
47 (defgroup gnus-article nil
49 :link '(custom-manual "(gnus)The Article Buffer")
52 (defgroup gnus-article-treat nil
53 "Treating article parts."
54 :link '(custom-manual "(gnus)Article Hiding")
57 (defgroup gnus-article-hiding nil
58 "Hiding article parts."
59 :link '(custom-manual "(gnus)Article Hiding")
62 (defgroup gnus-article-highlight nil
63 "Article highlighting."
64 :link '(custom-manual "(gnus)Article Highlighting")
68 (defgroup gnus-article-signature nil
70 :link '(custom-manual "(gnus)Article Signature")
73 (defgroup gnus-article-headers nil
75 :link '(custom-manual "(gnus)Hiding Headers")
78 (defgroup gnus-article-washing nil
79 "Special commands on articles."
80 :link '(custom-manual "(gnus)Article Washing")
83 (defgroup gnus-article-emphasis nil
84 "Fontisizing articles."
85 :link '(custom-manual "(gnus)Article Fontisizing")
88 (defgroup gnus-article-saving nil
90 :link '(custom-manual "(gnus)Saving Articles")
93 (defgroup gnus-article-mime nil
94 "Worshiping the MIME wonder."
95 :link '(custom-manual "(gnus)Using MIME")
98 (defgroup gnus-article-buttons nil
99 "Pushable buttons in the article buffer."
100 :link '(custom-manual "(gnus)Article Buttons")
101 :group 'gnus-article)
103 (defgroup gnus-article-various nil
104 "Other article options."
105 :link '(custom-manual "(gnus)Misc Article")
106 :group 'gnus-article)
108 (defcustom gnus-ignored-headers
109 '("^Path:" "^Expires:" "^Date-Received:" "^References:" "^Xref:" "^Lines:"
110 "^Relay-Version:" "^Message-ID:" "^Approved:" "^Sender:" "^Received:"
111 "^X-UIDL:" "^MIME-Version:" "^Return-Path:" "^In-Reply-To:"
112 "^Content-Type:" "^Content-Transfer-Encoding:" "^X-WebTV-Signature:"
113 "^X-MimeOLE:" "^X-MSMail-Priority:" "^X-Priority:" "^X-Loop:"
114 "^X-Authentication-Warning:" "^X-MIME-Autoconverted:" "^X-Face:"
115 "^X-Attribution:" "^X-Originating-IP:" "^Delivered-To:"
116 "^NNTP-[-A-Za-z]+:" "^Distribution:" "^X-no-archive:" "^X-Trace:"
117 "^X-Complaints-To:" "^X-NNTP-Posting-Host:" "^X-Orig.*:"
118 "^Abuse-Reports-To:" "^Cache-Post-Path:" "^X-Article-Creation-Date:"
119 "^X-Poster:" "^X-Mail2News-Path:" "^X-Server-Date:" "^X-Cache:"
120 "^Originator:" "^X-Problems-To:" "^X-Auth-User:" "^X-Post-Time:"
121 "^X-Admin:" "^X-UID:" "^Resent-[-A-Za-z]+:" "^X-Mailing-List:"
122 "^Precedence:" "^Original-[-A-Za-z]+:" "^X-filename:" "^X-Orcpt:"
123 "^Old-Received:" "^X-Pgp" "^X-Auth:" "^X-From-Line:"
124 "^X-Gnus-Article-Number:" "^X-Majordomo:" "^X-Url:" "^X-Sender:"
125 "^MBOX-Line" "^Priority:" "^X400-[-A-Za-z]+:"
126 "^Status:" "^X-Gnus-Mail-Source:" "^Cancel-Lock:"
127 "^X-FTN" "^X-EXP32-SerialNo:" "^Encoding:" "^Importance:"
128 "^Autoforwarded:" "^Original-Encoded-Information-Types:" "^X-Ya-Pop3:"
129 "^X-Face-Version:" "^X-Vms-To:" "^X-ML-NAME:" "^X-ML-COUNT:"
130 "^Mailing-List:" "^X-finfo:" "^X-md5sum:" "^X-md5sum-Origin:"
131 "^X-Sun-Charset:" "^X-Accept-Language:" "^X-Envelope-Sender:"
132 "^List-[A-Za-z]+:" "^X-Listprocessor-Version:"
133 "^X-Received:" "^X-Distribute:" "^X-Sequence:" "^X-Juno-Line-Breaks:"
134 "^X-Notes-Item:" "^X-MS-TNEF-Correlator:" "^x-uunet-gateway:"
135 "^X-Received:" "^Content-length:" "X-precedence:"
136 "^X-Authenticated-User:" "^X-Comment" "^X-Report:" "^X-Abuse-Info:"
137 "^X-HTTP-Proxy:" "^X-Mydeja-Info:" "^X-Copyright" "^X-No-Markup:"
138 "^X-Abuse-Info:" "^X-From_:" "^X-Accept-Language:" "^Errors-To:"
139 "^X-BeenThere:" "^X-Mailman-Version:" "^List-Help:" "^List-Post:"
140 "^List-Subscribe:" "^List-Id:" "^List-Unsubscribe:" "^List-Archive:"
141 "^X-Content-length:" "^X-Posting-Agent:" "^Original-Received:"
142 "^X-Request-PGP:" "^X-Fingerprint:" "^X-WRIEnvto:" "^X-WRIEnvfrom:"
143 "^X-Virus-Scanned:" "^X-Delivery-Agent:" "^Posted-Date:" "^X-Gateway:"
144 "^X-Local-Origin:" "^X-Local-Destination:")
145 "*All headers that start with this regexp will be hidden.
146 This variable can also be a list of regexps of headers to be ignored.
147 If `gnus-visible-headers' is non-nil, this variable will be ignored."
148 :type '(choice :custom-show nil
151 :group 'gnus-article-hiding)
153 (defcustom gnus-visible-headers
154 "^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:"
155 "*All headers that do not match this regexp will be hidden.
156 This variable can also be a list of regexp of headers to remain visible.
157 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
158 :type '(repeat :value-to-internal (lambda (widget value)
159 (custom-split-regexp-maybe value))
160 :match (lambda (widget value)
162 (widget-editable-list-match widget value)))
164 :group 'gnus-article-hiding)
166 (defcustom gnus-sorted-header-list
167 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
168 "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
169 "*This variable is a list of regular expressions.
170 If it is non-nil, headers that match the regular expressions will
171 be placed first in the article buffer in the sequence specified by
173 :type '(repeat regexp)
174 :group 'gnus-article-hiding)
176 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
177 "Headers that are only to be displayed if they have interesting data.
178 Possible values in this list are:
180 'empty Headers with no content.
181 'newsgroups Newsgroup identical to Gnus group.
182 'to-address To identical to To-address.
183 'followup-to Followup-to identical to Newsgroups.
184 'reply-to Reply-to identical to From.
185 'date Date less than four days old.
186 'long-to To and/or Cc longer than 1024 characters.
187 'many-to Multiple To and/or Cc."
188 :type '(set (const :tag "Headers with no content." empty)
189 (const :tag "Newsgroups identical to Gnus group." newsgroups)
190 (const :tag "To identical to To-address." to-address)
191 (const :tag "Followup-to identical to Newsgroups." followup-to)
192 (const :tag "Reply-to identical to From." reply-to)
193 (const :tag "Date less than four days old." date)
194 (const :tag "To and/or Cc longer than 1024 characters." long-to)
195 (const :tag "Multiple To and/or Cc headers." many-to))
196 :group 'gnus-article-hiding)
198 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
199 "Regexp matching signature separator.
200 This can also be a list of regexps. In that case, it will be checked
201 from head to tail looking for a separator. Searches will be done from
202 the end of the buffer."
203 :type '(repeat string)
204 :group 'gnus-article-signature)
206 (defcustom gnus-signature-limit nil
207 "Provide a limit to what is considered a signature.
208 If it is a number, no signature may not be longer (in characters) than
209 that number. If it is a floating point number, no signature may be
210 longer (in lines) than that number. If it is a function, the function
211 will be called without any parameters, and if it returns nil, there is
212 no signature in the buffer. If it is a string, it will be used as a
213 regexp. If it matches, the text in question is not a signature."
214 :type '(choice (integer :value 200)
216 (function :value fun)
217 (regexp :value ".*"))
218 :group 'gnus-article-signature)
220 (defcustom gnus-hidden-properties '(invisible t intangible t)
221 "Property list to use for hiding text."
223 :group 'gnus-article-hiding)
225 ;; Fixme: This isn't the right thing for mixed graphical and and
226 ;; non-graphical frames in a session.
227 (defcustom gnus-article-x-face-command
228 (if (featurep 'xemacs)
229 (if (or (gnus-image-type-available-p 'xface)
230 (gnus-image-type-available-p 'xpm))
231 'gnus-xmas-article-display-xface
232 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | ee -")
233 (if (gnus-image-type-available-p 'xbm)
234 'gnus-article-display-xface
235 (if gnus-article-compface-xbm
236 "{ echo '/* Width=48, Height=48 */'; uncompface; } | display -"
237 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | \
239 "*String or function to be executed to display an X-Face header.
240 If it is a string, the command will be executed in a sub-shell
241 asynchronously. The compressed face will be piped to this command."
242 :type `(choice string
244 ,(if (featurep 'xemacs)
245 'gnus-xmas-article-display-xface
246 'gnus-article-display-xface))
249 :group 'gnus-article-washing)
251 (defcustom gnus-article-x-face-too-ugly nil
252 "Regexp matching posters whose face shouldn't be shown automatically."
253 :type '(choice regexp (const nil))
254 :group 'gnus-article-washing)
256 (defcustom gnus-article-banner-alist nil
257 "Banner alist for stripping.
259 ((egroups . \"^[ \\t\\n]*-------------------+\\\\( \\\\(e\\\\|Yahoo! \\\\)Groups Sponsor -+\\\\)?....\\n\\\\(.+\\n\\\\)+\"))"
261 :type '(repeat (cons symbol regexp))
262 :group 'gnus-article-washing)
264 (gnus-define-group-parameter
267 "Alist of regexps (to match group names) and banner."
268 :variable-group gnus-article-washing
270 '(choice :tag "Banner"
272 (const :tag "Remove signature" signature)
273 (symbol :tag "Item in `gnus-article-banner-alist'" none)
275 (const :tag "None" nil))
277 "If non-nil, specify how to remove `banners' from articles.
279 Symbol `signature' means to remove signatures delimited by
280 `gnus-signature-separator'. Any other symbol is used to look up a
281 regular expression to match the banner in `gnus-article-banner-alist'.
282 A string is used as a regular expression to match the banner
285 (defcustom gnus-emphasis-alist
287 "\\(\\s-\\|^\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\\(\\s-\\|[-,;:\"]\\s-\\|[?!.]+\\s-\\|\\s)\\)")
289 '(("_" "_" underline)
292 ("_/" "/_" underline-italic)
293 ("_\\*" "\\*_" underline-bold)
294 ("\\*/" "/\\*" bold-italic)
295 ("_\\*/" "/\\*_" underline-bold-italic))))
296 `(("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
297 2 3 gnus-emphasis-underline)
301 (format format (car spec) (cadr spec))
302 2 3 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
304 "*Alist that says how to fontify certain phrases.
305 Each item looks like this:
307 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
309 The first element is a regular expression to be matched. The second
310 is a number that says what regular expression grouping used to find
311 the entire emphasized word. The third is a number that says what
312 regexp grouping should be displayed and highlighted. The fourth
313 is the face used for highlighting."
314 :type '(repeat (list :value ("" 0 0 default)
316 (integer :tag "Match group")
317 (integer :tag "Emphasize group")
319 :group 'gnus-article-emphasis)
321 (defcustom gnus-emphasize-whitespace-regexp "^[ \t]+\\|[ \t]*\n"
322 "A regexp to describe whitespace which should not be emphasized.
323 Typical values are \"^[ \\t]+\\\\|[ \\t]*\\n\" and \"[ \\t]+\\\\|[ \\t]*\\n\".
324 The former avoids underlining of leading and trailing whitespace,
325 and the latter avoids underlining any whitespace at all."
327 :group 'gnus-article-emphasis
330 (defface gnus-emphasis-bold '((t (:bold t)))
331 "Face used for displaying strong emphasized text (*word*)."
332 :group 'gnus-article-emphasis)
334 (defface gnus-emphasis-italic '((t (:italic t)))
335 "Face used for displaying italic emphasized text (/word/)."
336 :group 'gnus-article-emphasis)
338 (defface gnus-emphasis-underline '((t (:underline t)))
339 "Face used for displaying underlined emphasized text (_word_)."
340 :group 'gnus-article-emphasis)
342 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
343 "Face used for displaying underlined bold emphasized text (_*word*_)."
344 :group 'gnus-article-emphasis)
346 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
347 "Face used for displaying underlined italic emphasized text (_/word/_)."
348 :group 'gnus-article-emphasis)
350 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
351 "Face used for displaying bold italic emphasized text (/*word*/)."
352 :group 'gnus-article-emphasis)
354 (defface gnus-emphasis-underline-bold-italic
355 '((t (:bold t :italic t :underline t)))
356 "Face used for displaying underlined bold italic emphasized text.
357 Esample: (_/*word*/_)."
358 :group 'gnus-article-emphasis)
360 (defface gnus-emphasis-highlight-words
361 '((t (:background "black" :foreground "yellow")))
362 "Face used for displaying highlighted words."
363 :group 'gnus-article-emphasis)
365 (defcustom gnus-article-time-format "%a, %b %d %Y %T %Z"
366 "Format for display of Date headers in article bodies.
367 See `format-time-string' for the possible values.
369 The variable can also be function, which should return a complete Date
370 header. The function is called with one argument, the time, which can
371 be fed to `format-time-string'."
372 :type '(choice string symbol)
373 :link '(custom-manual "(gnus)Article Date")
374 :group 'gnus-article-washing)
377 (autoload 'mail-extract-address-components "mail-extr"))
379 (defcustom gnus-save-all-headers t
380 "*If non-nil, don't remove any headers before saving."
381 :group 'gnus-article-saving
384 (defcustom gnus-prompt-before-saving 'always
385 "*This variable says how much prompting is to be done when saving articles.
386 If it is nil, no prompting will be done, and the articles will be
387 saved to the default files. If this variable is `always', each and
388 every article that is saved will be preceded by a prompt, even when
389 saving large batches of articles. If this variable is neither nil not
390 `always', there the user will be prompted once for a file name for
391 each invocation of the saving commands."
392 :group 'gnus-article-saving
393 :type '(choice (item always)
394 (item :tag "never" nil)
395 (sexp :tag "once" :format "%t\n" :value t)))
397 (defcustom gnus-saved-headers gnus-visible-headers
398 "Headers to keep if `gnus-save-all-headers' is nil.
399 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
400 If that variable is nil, however, all headers that match this regexp
401 will be kept while the rest will be deleted before saving."
402 :group 'gnus-article-saving
405 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
406 "A function to save articles in your favourite format.
407 The function must be interactively callable (in other words, it must
408 be an Emacs command).
410 Gnus provides the following functions:
412 * gnus-summary-save-in-rmail (Rmail format)
413 * gnus-summary-save-in-mail (Unix mail format)
414 * gnus-summary-save-in-folder (MH folder)
415 * gnus-summary-save-in-file (article format)
416 * gnus-summary-save-body-in-file (article body)
417 * gnus-summary-save-in-vm (use VM's folder format)
418 * gnus-summary-write-to-file (article format -- overwrite)."
419 :group 'gnus-article-saving
420 :type '(radio (function-item gnus-summary-save-in-rmail)
421 (function-item gnus-summary-save-in-mail)
422 (function-item gnus-summary-save-in-folder)
423 (function-item gnus-summary-save-in-file)
424 (function-item gnus-summary-save-body-in-file)
425 (function-item gnus-summary-save-in-vm)
426 (function-item gnus-summary-write-to-file)))
428 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
429 "A function generating a file name to save articles in Rmail format.
430 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
431 :group 'gnus-article-saving
434 (defcustom gnus-mail-save-name 'gnus-plain-save-name
435 "A function generating a file name to save articles in Unix mail format.
436 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
437 :group 'gnus-article-saving
440 (defcustom gnus-folder-save-name 'gnus-folder-save-name
441 "A function generating a file name to save articles in MH folder.
442 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
443 :group 'gnus-article-saving
446 (defcustom gnus-file-save-name 'gnus-numeric-save-name
447 "A function generating a file name to save articles in article format.
448 The function is called with NEWSGROUP, HEADERS, and optional
450 :group 'gnus-article-saving
453 (defcustom gnus-split-methods
454 '((gnus-article-archive-name)
455 (gnus-article-nndoc-name))
456 "*Variable used to suggest where articles are to be saved.
457 For instance, if you would like to save articles related to Gnus in
458 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
459 you could set this variable to something like:
461 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
462 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
464 This variable is an alist where the where the key is the match and the
465 value is a list of possible files to save in if the match is non-nil.
467 If the match is a string, it is used as a regexp match on the
468 article. If the match is a symbol, that symbol will be funcalled
469 from the buffer of the article to be saved with the newsgroup as the
470 parameter. If it is a list, it will be evaled in the same buffer.
472 If this form or function returns a string, this string will be used as
473 a possible file name; and if it returns a non-nil list, that list will
474 be used as possible file names."
475 :group 'gnus-article-saving
476 :type '(repeat (choice (list :value (fun) function)
477 (cons :value ("" "") regexp (repeat string))
480 (defcustom gnus-page-delimiter "^\^L"
481 "*Regexp describing what to use as article page delimiters.
482 The default value is \"^\^L\", which is a form linefeed at the
483 beginning of a line."
485 :group 'gnus-article-various)
487 (defcustom gnus-article-mode-line-format "Gnus: %g [%w] %S%m"
488 "*The format specification for the article mode line.
489 See `gnus-summary-mode-line-format' for a closer description.
491 The following additional specs are available:
493 %w The article washing status.
494 %m The number of MIME parts in the article."
496 :group 'gnus-article-various)
498 (defcustom gnus-article-mode-hook nil
499 "*A hook for Gnus article mode."
501 :group 'gnus-article-various)
503 (when (featurep 'xemacs)
504 ;; Extracted from gnus-xmas-define in order to preserve user settings
505 (when (fboundp 'turn-off-scroll-in-place)
506 (add-hook 'gnus-article-mode-hook 'turn-off-scroll-in-place))
507 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
508 (add-hook 'gnus-article-mode-hook 'gnus-xmas-article-menu-add))
510 (defcustom gnus-article-menu-hook nil
511 "*Hook run after the creation of the article mode menu."
513 :group 'gnus-article-various)
515 (defcustom gnus-article-prepare-hook nil
516 "*A hook called after an article has been prepared in the article buffer."
518 :group 'gnus-article-various)
520 (defcustom gnus-article-hide-pgp-hook nil
521 "*A hook called after successfully hiding a PGP signature."
523 :group 'gnus-article-various)
525 (defcustom gnus-article-button-face 'bold
526 "Face used for highlighting buttons in the article buffer.
528 An article button is a piece of text that you can activate by pressing
529 `RET' or `mouse-2' above it."
531 :group 'gnus-article-buttons)
533 (defcustom gnus-article-mouse-face 'highlight
534 "Face used for mouse highlighting in the article buffer.
536 Article buttons will be displayed in this face when the cursor is
539 :group 'gnus-article-buttons)
541 (defcustom gnus-signature-face 'gnus-signature-face
542 "Face used for highlighting a signature in the article buffer.
543 Obsolete; use the face `gnus-signature-face' for customizations instead."
545 :group 'gnus-article-highlight
546 :group 'gnus-article-signature)
548 (defface gnus-signature-face
551 "Face used for highlighting a signature in the article buffer."
552 :group 'gnus-article-highlight
553 :group 'gnus-article-signature)
555 (defface gnus-header-from-face
558 (:foreground "spring green"))
561 (:foreground "red3"))
564 "Face used for displaying from headers."
565 :group 'gnus-article-headers
566 :group 'gnus-article-highlight)
568 (defface gnus-header-subject-face
571 (:foreground "SeaGreen3"))
574 (:foreground "red4"))
576 (:bold t :italic t)))
577 "Face used for displaying subject headers."
578 :group 'gnus-article-headers
579 :group 'gnus-article-highlight)
581 (defface gnus-header-newsgroups-face
584 (:foreground "yellow" :italic t))
587 (:foreground "MidnightBlue" :italic t))
590 "Face used for displaying newsgroups headers."
591 :group 'gnus-article-headers
592 :group 'gnus-article-highlight)
594 (defface gnus-header-name-face
597 (:foreground "SeaGreen"))
600 (:foreground "maroon"))
603 "Face used for displaying header names."
604 :group 'gnus-article-headers
605 :group 'gnus-article-highlight)
607 (defface gnus-header-content-face
610 (:foreground "forest green" :italic t))
613 (:foreground "indianred4" :italic t))
615 (:italic t))) "Face used for displaying header content."
616 :group 'gnus-article-headers
617 :group 'gnus-article-highlight)
619 (defcustom gnus-header-face-alist
620 '(("From" nil gnus-header-from-face)
621 ("Subject" nil gnus-header-subject-face)
622 ("Newsgroups:.*," nil gnus-header-newsgroups-face)
623 ("" gnus-header-name-face gnus-header-content-face))
624 "*Controls highlighting of article header.
626 An alist of the form (HEADER NAME CONTENT).
628 HEADER is a regular expression which should match the name of an
629 header header and NAME and CONTENT are either face names or nil.
631 The name of each header field will be displayed using the face
632 specified by the first element in the list where HEADER match the
633 header name and NAME is non-nil. Similarly, the content will be
634 displayed by the first non-nil matching CONTENT face."
635 :group 'gnus-article-headers
636 :group 'gnus-article-highlight
637 :type '(repeat (list (regexp :tag "Header")
639 (item :tag "skip" nil)
640 (face :value default))
641 (choice :tag "Content"
642 (item :tag "skip" nil)
643 (face :value default)))))
645 (defcustom gnus-article-decode-hook
646 '(article-decode-charset article-decode-encoded-words
647 article-decode-group-name)
648 "*Hook run to decode charsets in articles."
649 :group 'gnus-article-headers
652 (defcustom gnus-display-mime-function 'gnus-display-mime
653 "Function to display MIME articles."
654 :group 'gnus-article-mime
657 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
658 "Function used to decode headers.")
660 (defvar gnus-article-dumbquotes-map
679 "Table for MS-to-Latin1 translation.")
681 (defcustom gnus-ignored-mime-types nil
682 "List of MIME types that should be ignored by Gnus."
684 :group 'gnus-article-mime
685 :type '(repeat regexp))
687 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
688 "List of MIME types that should not be given buttons when rendered inline.
689 See also `gnus-buttonized-mime-types' which may override this variable."
691 :group 'gnus-article-mime
692 :type '(repeat regexp))
694 (defcustom gnus-buttonized-mime-types nil
695 "List of MIME types that should be given buttons when rendered inline.
696 If set, this variable overrides `gnus-unbuttonized-mime-types'.
697 To see e.g. security buttons you could set this to
698 `(\"multipart/signed\")'."
700 :group 'gnus-article-mime
701 :type '(repeat regexp))
703 (defcustom gnus-article-mime-part-function nil
704 "Function called with a MIME handle as the argument.
705 This is meant for people who want to do something automatic based
706 on parts -- for instance, adding Vcard info to a database."
707 :group 'gnus-article-mime
710 (defcustom gnus-mime-multipart-functions nil
711 "An alist of MIME types to functions to display them."
713 :group 'gnus-article-mime
716 (defcustom gnus-article-date-lapsed-new-header nil
717 "Whether the X-Sent and Date headers can coexist.
718 When using `gnus-treat-date-lapsed', the \"X-Sent:\" header will
719 either replace the old \"Date:\" header (if this variable is nil), or
720 be added below it (otherwise)."
722 :group 'gnus-article-headers
725 (defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
726 "Function called with a MIME handle as the argument.
727 This is meant for people who want to view first matched part.
728 For `undisplayed-alternative' (default), the first undisplayed
729 part or alternative part is used. For `undisplayed', the first
730 undisplayed part is used. For a function, the first part which
731 the function return `t' is used. For `nil', the first part is
734 :group 'gnus-article-mime
736 (item :tag "first" :value nil)
737 (item :tag "undisplayed" :value undisplayed)
738 (item :tag "undisplayed or alternative"
739 :value undisplayed-alternative)
742 (defcustom gnus-mime-action-alist
743 '(("save to file" . gnus-mime-save-part)
744 ("save and strip" . gnus-mime-save-part-and-strip)
745 ("display as text" . gnus-mime-inline-part)
746 ("view the part" . gnus-mime-view-part)
747 ("pipe to command" . gnus-mime-pipe-part)
748 ("toggle display" . gnus-article-press-button)
749 ("toggle display" . gnus-article-view-part-as-charset)
750 ("view as type" . gnus-mime-view-part-as-type)
751 ("internalize type" . gnus-mime-internalize-part)
752 ("externalize type" . gnus-mime-externalize-part))
753 "An alist of actions that run on the MIME attachment."
754 :group 'gnus-article-mime
755 :type '(repeat (cons (string :tag "name")
758 (defcustom gnus-mime-action-alist
759 '(("save to file" . gnus-mime-save-part)
760 ("display as text" . gnus-mime-inline-part)
761 ("view the part" . gnus-mime-view-part)
762 ("pipe to command" . gnus-mime-pipe-part)
763 ("toggle display" . gnus-article-press-button)
764 ("view as type" . gnus-mime-view-part-as-type)
765 ("internalize type" . gnus-mime-internalize-part)
766 ("externalize type" . gnus-mime-externalize-part))
767 "An alist of actions that run on the MIME attachment."
769 :group 'gnus-article-mime
770 :type '(repeat (cons (string :tag "name")
774 ;;; The treatment variables
777 (defvar gnus-part-display-hook nil
778 "Hook called on parts that are to receive treatment.")
780 (defvar gnus-article-treat-custom
781 '(choice (const :tag "Off" nil)
783 (const :tag "Header" head)
784 (const :tag "Last" last)
785 (integer :tag "Less")
786 (repeat :tag "Groups" regexp)
787 (sexp :tag "Predicate")))
789 (defvar gnus-article-treat-head-custom
790 '(choice (const :tag "Off" nil)
791 (const :tag "Header" head)))
793 (defvar gnus-article-treat-types '("text/plain")
796 (defvar gnus-inhibit-treatment nil
797 "Whether to inhibit treatment.")
799 (defcustom gnus-treat-highlight-signature '(or last (typep "text/x-vcard"))
800 "Highlight the signature.
801 Valid values are nil, t, `head', `last', an integer or a predicate.
802 See Info node `(gnus)Customizing Articles'."
803 :group 'gnus-article-treat
804 :type gnus-article-treat-custom)
805 (put 'gnus-treat-highlight-signature 'highlight t)
807 (defcustom gnus-treat-buttonize 100000
809 Valid values are nil, t, `head', `last', an integer or a predicate.
810 See the manual for details."
811 :group 'gnus-article-treat
812 :type gnus-article-treat-custom)
813 (put 'gnus-treat-buttonize 'highlight t)
815 (defcustom gnus-treat-buttonize-head 'head
816 "Add buttons to the head.
817 Valid values are nil, t, `head', `last', an integer or a predicate.
818 See the manual for details."
819 :group 'gnus-article-treat
820 :type gnus-article-treat-head-custom)
821 (put 'gnus-treat-buttonize-head 'highlight t)
823 (defcustom gnus-treat-emphasize
824 (and (or window-system
826 (>= (string-to-number emacs-version) 21))
829 Valid values are nil, t, `head', `last', an integer or a predicate.
830 See the manual for details."
831 :group 'gnus-article-treat
832 :type gnus-article-treat-custom)
833 (put 'gnus-treat-emphasize 'highlight t)
835 (defcustom gnus-treat-strip-cr nil
836 "Remove carriage returns.
837 Valid values are nil, t, `head', `last', an integer or a predicate.
838 See the manual for details."
839 :group 'gnus-article-treat
840 :type gnus-article-treat-custom)
842 (defcustom gnus-treat-leading-whitespace nil
843 "Remove leading whitespace in headers.
844 Valid values are nil, t, `head', `last', an integer or a predicate.
845 See the manual for details."
846 :group 'gnus-article-treat
847 :type gnus-article-treat-custom)
849 (defcustom gnus-treat-hide-headers 'head
851 Valid values are nil, t, `head', `last', an integer or a predicate.
852 See the manual for details."
853 :group 'gnus-article-treat
854 :type gnus-article-treat-head-custom)
856 (defcustom gnus-treat-hide-boring-headers nil
857 "Hide boring headers.
858 Valid values are nil, t, `head', `last', an integer or a predicate.
859 See the manual for details."
860 :group 'gnus-article-treat
861 :type gnus-article-treat-head-custom)
863 (defcustom gnus-treat-hide-signature nil
865 Valid values are nil, t, `head', `last', an integer or a predicate.
866 See the manual for details."
867 :group 'gnus-article-treat
868 :type gnus-article-treat-custom)
870 (defcustom gnus-treat-fill-article nil
872 Valid values are nil, t, `head', `last', an integer or a predicate.
873 See the manual for details."
874 :group 'gnus-article-treat
875 :type gnus-article-treat-custom)
877 (defcustom gnus-treat-hide-citation nil
879 Valid values are nil, t, `head', `last', an integer or a predicate.
880 See the manual for details."
881 :group 'gnus-article-treat
882 :type gnus-article-treat-custom)
884 (defcustom gnus-treat-hide-citation-maybe nil
886 Valid values are nil, t, `head', `last', an integer or a predicate.
887 See the manual for details."
888 :group 'gnus-article-treat
889 :type gnus-article-treat-custom)
891 (defcustom gnus-treat-strip-list-identifiers 'head
892 "Strip list identifiers from `gnus-list-identifiers`.
893 Valid values are nil, t, `head', `last', an integer or a predicate.
894 See the manual for details."
896 :group 'gnus-article-treat
897 :type gnus-article-treat-custom)
899 (defcustom gnus-treat-strip-pgp t
900 "Strip PGP signatures.
901 Valid values are nil, t, `head', `last', an integer or a predicate.
902 See the manual for details."
903 :group 'gnus-article-treat
904 :type gnus-article-treat-custom)
906 (defcustom gnus-treat-strip-pem nil
907 "Strip PEM signatures.
908 Valid values are nil, t, `head', `last', an integer or a predicate.
909 See the manual for details."
910 :group 'gnus-article-treat
911 :type gnus-article-treat-custom)
913 (defcustom gnus-treat-strip-banner t
914 "Strip banners from articles.
915 The banner to be stripped is specified in the `banner' group parameter.
916 Valid values are nil, t, `head', `last', an integer or a predicate.
917 See the manual for details."
918 :group 'gnus-article-treat
919 :type gnus-article-treat-custom)
921 (defcustom gnus-treat-highlight-headers 'head
922 "Highlight the headers.
923 Valid values are nil, t, `head', `last', an integer or a predicate.
924 See the manual for details."
925 :group 'gnus-article-treat
926 :type gnus-article-treat-head-custom)
927 (put 'gnus-treat-highlight-headers 'highlight t)
929 (defcustom gnus-treat-highlight-citation t
930 "Highlight cited text.
931 Valid values are nil, t, `head', `last', an integer or a predicate.
932 See the manual for details."
933 :group 'gnus-article-treat
934 :type gnus-article-treat-custom)
935 (put 'gnus-treat-highlight-citation 'highlight t)
937 (defcustom gnus-treat-date-ut nil
938 "Display the Date in UT (GMT).
939 Valid values are nil, t, `head', `last', an integer or a predicate.
940 See the manual for details."
941 :group 'gnus-article-treat
942 :type gnus-article-treat-head-custom)
944 (defcustom gnus-treat-date-local nil
945 "Display the Date in the local timezone.
946 Valid values are nil, t, `head', `last', an integer or a predicate.
947 See the manual for details."
948 :group 'gnus-article-treat
949 :type gnus-article-treat-head-custom)
951 (defcustom gnus-treat-date-english nil
952 "Display the Date in a format that can be read aloud in English.
953 Valid values are nil, t, `head', `last', an integer or a predicate.
954 See the manual for details."
955 :group 'gnus-article-treat
956 :type gnus-article-treat-head-custom)
958 (defcustom gnus-treat-date-lapsed nil
959 "Display the Date header in a way that says how much time has elapsed.
960 Valid values are nil, t, `head', `last', an integer or a predicate.
961 See the manual for details."
962 :group 'gnus-article-treat
963 :type gnus-article-treat-head-custom)
965 (defcustom gnus-treat-date-original nil
966 "Display the date in the original timezone.
967 Valid values are nil, t, `head', `last', an integer or a predicate.
968 See the manual for details."
969 :group 'gnus-article-treat
970 :type gnus-article-treat-head-custom)
972 (defcustom gnus-treat-date-iso8601 nil
973 "Display the date in the ISO8601 format.
974 Valid values are nil, t, `head', `last', an integer or a predicate.
975 See the manual for details."
977 :group 'gnus-article-treat
978 :type gnus-article-treat-head-custom)
980 (defcustom gnus-treat-date-user-defined nil
981 "Display the date in a user-defined format.
982 The format is defined by the `gnus-article-time-format' variable.
983 Valid values are nil, t, `head', `last', an integer or a predicate.
984 See the manual for details."
985 :group 'gnus-article-treat
986 :type gnus-article-treat-head-custom)
988 (defcustom gnus-treat-strip-headers-in-body t
989 "Strip the X-No-Archive header line from the beginning of the body.
990 Valid values are nil, t, `head', `last', an integer or a predicate.
991 See the manual for details."
993 :group 'gnus-article-treat
994 :type gnus-article-treat-custom)
996 (defcustom gnus-treat-strip-trailing-blank-lines nil
997 "Strip trailing blank lines.
998 Valid values are nil, t, `head', `last', an integer or a predicate.
999 See the manual for details."
1000 :group 'gnus-article-treat
1001 :type gnus-article-treat-custom)
1003 (defcustom gnus-treat-strip-leading-blank-lines nil
1004 "Strip leading blank lines.
1005 Valid values are nil, t, `head', `last', an integer or a predicate.
1006 See the manual for details."
1007 :group 'gnus-article-treat
1008 :type gnus-article-treat-custom)
1010 (defcustom gnus-treat-strip-multiple-blank-lines nil
1011 "Strip multiple blank lines.
1012 Valid values are nil, t, `head', `last', an integer or a predicate.
1013 See the manual for details."
1014 :group 'gnus-article-treat
1015 :type gnus-article-treat-custom)
1017 (defcustom gnus-treat-unfold-headers 'head
1018 "Unfold folded header lines.
1019 Valid values are nil, t, `head', `last', an integer or a predicate.
1020 See the manual for details."
1021 :group 'gnus-article-treat
1022 :type gnus-article-treat-custom)
1024 (defcustom gnus-treat-fold-newsgroups 'head
1025 "Fold the Newsgroups and Followup-To headers.
1026 Valid values are nil, t, `head', `last', an integer or a predicate.
1027 See the manual for details."
1028 :group 'gnus-article-treat
1029 :type gnus-article-treat-custom)
1031 (defcustom gnus-treat-overstrike t
1032 "Treat overstrike highlighting.
1033 Valid values are nil, t, `head', `last', an integer or a predicate.
1034 See the manual for details."
1035 :group 'gnus-article-treat
1036 :type gnus-article-treat-custom)
1037 (put 'gnus-treat-overstrike 'highlight t)
1039 (defcustom gnus-treat-display-xface
1040 (and (or (and (fboundp 'image-type-available-p)
1041 (image-type-available-p 'xbm)
1042 (string-match "^0x" (shell-command-to-string "uncompface")))
1043 (and (featurep 'xemacs)
1046 "Display X-Face headers.
1047 Valid values are nil, t, `head', `last', an integer or a predicate.
1048 See the manual for details."
1049 :group 'gnus-article-treat
1051 :type gnus-article-treat-head-custom)
1052 (put 'gnus-treat-display-xface 'highlight t)
1054 (defcustom gnus-treat-display-smileys
1055 (if (or (and (featurep 'xemacs)
1057 (and (fboundp 'image-type-available-p)
1058 (image-type-available-p 'pbm)))
1061 Valid values are nil, t, `head', `last', an integer or a predicate.
1062 See the manual for details."
1063 :group 'gnus-article-treat
1065 :type gnus-article-treat-custom)
1066 (put 'gnus-treat-display-smileys 'highlight t)
1068 (defcustom gnus-treat-from-picon
1069 (if (gnus-image-type-available-p 'xpm)
1071 "Display picons in the From header.
1072 Valid values are nil, t, `head', `last', an integer or a predicate.
1073 See the manual for details."
1074 :group 'gnus-article-treat
1075 :type gnus-article-treat-head-custom)
1076 (put 'gnus-treat-from-picon 'highlight t)
1078 (defcustom gnus-treat-mail-picon
1079 (if (gnus-image-type-available-p 'xpm)
1081 "Display picons in To and Cc headers.
1082 Valid values are nil, t, `head', `last', an integer or a predicate.
1083 See the manual for details."
1084 :group 'gnus-article-treat
1085 :type gnus-article-treat-head-custom)
1086 (put 'gnus-treat-mail-picon 'highlight t)
1088 (defcustom gnus-treat-newsgroups-picon
1089 (if (gnus-image-type-available-p 'xpm)
1091 "Display picons in the Newsgroups and Followup-To headers.
1092 Valid values are nil, t, `head', `last', an integer or a predicate.
1093 See the manual for details."
1094 :group 'gnus-article-treat
1095 :type gnus-article-treat-head-custom)
1096 (put 'gnus-treat-newsgroups-picon 'highlight t)
1098 (defcustom gnus-treat-body-boundary
1099 (if (or gnus-treat-newsgroups-picon
1100 gnus-treat-mail-picon
1101 gnus-treat-from-picon)
1103 "Draw a boundary at the end of the headers.
1104 Valid values are nil, t, `head', `last', an integer or a predicate.
1105 See the manual for details."
1107 :group 'gnus-article-treat
1108 :type gnus-article-treat-custom)
1110 (defcustom gnus-treat-capitalize-sentences nil
1111 "Capitalize sentence-starting words.
1112 Valid values are nil, t, `head', `last', an integer or a predicate.
1113 See the manual for details."
1115 :group 'gnus-article-treat
1116 :type gnus-article-treat-custom)
1118 (defcustom gnus-treat-fill-long-lines nil
1120 Valid values are nil, t, `head', `last', an integer or a predicate.
1121 See the manual for details."
1122 :group 'gnus-article-treat
1123 :type gnus-article-treat-custom)
1125 (defcustom gnus-treat-play-sounds nil
1127 Valid values are nil, t, `head', `last', an integer or a predicate.
1128 See the manual for details."
1130 :group 'gnus-article-treat
1131 :type gnus-article-treat-custom)
1133 (defcustom gnus-treat-translate nil
1134 "Translate articles from one language to another.
1135 Valid values are nil, t, `head', `last', an integer or a predicate.
1136 See the manual for details."
1138 :group 'gnus-article-treat
1139 :type gnus-article-treat-custom)
1141 (defcustom gnus-treat-x-pgp-sig nil
1143 To automatically treat X-PGP-Sig, set it to head.
1144 Valid values are nil, t, `head', `last', an integer or a predicate.
1145 See the manual for details."
1146 :group 'gnus-article-treat
1147 :group 'mime-security
1148 :type gnus-article-treat-custom)
1150 (defvar gnus-article-encrypt-protocol-alist
1151 '(("PGP" . mml2015-self-encrypt)))
1153 ;; Set to nil if more than one protocol added to
1154 ;; gnus-article-encrypt-protocol-alist.
1155 (defcustom gnus-article-encrypt-protocol "PGP"
1156 "The protocol used for encrypt articles.
1157 It is a string, such as \"PGP\". If nil, ask user."
1159 :group 'mime-security)
1161 ;;; Internal variables
1163 (defvar gnus-english-month-names
1164 '("January" "February" "March" "April" "May" "June" "July" "August"
1165 "September" "October" "November" "December"))
1167 (defvar article-goto-body-goes-to-point-min-p nil)
1168 (defvar gnus-article-wash-types nil)
1169 (defvar gnus-article-emphasis-alist nil)
1171 (defvar gnus-article-mime-handle-alist-1 nil)
1172 (defvar gnus-treatment-function-alist
1173 '((gnus-treat-x-pgp-sig gnus-article-verify-x-pgp-sig)
1174 (gnus-treat-strip-banner gnus-article-strip-banner)
1175 (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
1176 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1177 (gnus-treat-buttonize gnus-article-add-buttons)
1178 (gnus-treat-fill-article gnus-article-fill-cited-article)
1179 (gnus-treat-fill-long-lines gnus-article-fill-long-lines)
1180 (gnus-treat-strip-cr gnus-article-remove-cr)
1181 (gnus-treat-display-xface gnus-article-display-x-face)
1182 (gnus-treat-date-ut gnus-article-date-ut)
1183 (gnus-treat-date-local gnus-article-date-local)
1184 (gnus-treat-date-english gnus-article-date-english)
1185 (gnus-treat-date-lapsed gnus-article-date-lapsed)
1186 (gnus-treat-date-original gnus-article-date-original)
1187 (gnus-treat-date-user-defined gnus-article-date-user)
1188 (gnus-treat-date-iso8601 gnus-article-date-iso8601)
1189 (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
1190 (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
1191 (gnus-treat-hide-signature gnus-article-hide-signature)
1192 (gnus-treat-hide-citation gnus-article-hide-citation)
1193 (gnus-treat-hide-citation-maybe gnus-article-hide-citation-maybe)
1194 (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
1195 (gnus-treat-leading-whitespace gnus-article-remove-leading-whitespace)
1196 (gnus-treat-strip-pgp gnus-article-hide-pgp)
1197 (gnus-treat-strip-pem gnus-article-hide-pem)
1198 (gnus-treat-from-picon gnus-treat-from-picon)
1199 (gnus-treat-mail-picon gnus-treat-mail-picon)
1200 (gnus-treat-newsgroups-picon gnus-treat-newsgroups-picon)
1201 (gnus-treat-highlight-headers gnus-article-highlight-headers)
1202 (gnus-treat-highlight-citation gnus-article-highlight-citation)
1203 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1204 (gnus-treat-strip-trailing-blank-lines
1205 gnus-article-remove-trailing-blank-lines)
1206 (gnus-treat-strip-leading-blank-lines
1207 gnus-article-strip-leading-blank-lines)
1208 (gnus-treat-strip-multiple-blank-lines
1209 gnus-article-strip-multiple-blank-lines)
1210 (gnus-treat-overstrike gnus-article-treat-overstrike)
1211 (gnus-treat-unfold-headers gnus-article-treat-unfold-headers)
1212 (gnus-treat-fold-newsgroups gnus-article-treat-fold-newsgroups)
1213 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
1214 (gnus-treat-display-smileys gnus-smiley-display)
1215 (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
1216 (gnus-treat-emphasize gnus-article-emphasize)
1217 (gnus-treat-body-boundary gnus-article-treat-body-boundary)
1218 (gnus-treat-play-sounds gnus-earcon-display)))
1220 (defvar gnus-article-mime-handle-alist nil)
1221 (defvar article-lapsed-timer nil)
1222 (defvar gnus-article-current-summary nil)
1224 (defvar gnus-article-mode-syntax-table
1225 (let ((table (copy-syntax-table text-mode-syntax-table)))
1226 ;; This causes the citation match run O(2^n).
1227 ;; (modify-syntax-entry ?- "w" table)
1228 (modify-syntax-entry ?> ")" table)
1229 (modify-syntax-entry ?< "(" table)
1231 "Syntax table used in article mode buffers.
1232 Initialized from `text-mode-syntax-table.")
1234 (defvar gnus-save-article-buffer nil)
1236 (defvar gnus-article-mode-line-format-alist
1237 (nconc '((?w (gnus-article-wash-status) ?s)
1238 (?m (gnus-article-mime-part-status) ?s))
1239 gnus-summary-mode-line-format-alist))
1241 (defvar gnus-number-of-articles-to-be-saved nil)
1243 (defvar gnus-inhibit-hiding nil)
1245 ;;; Macros for dealing with the article buffer.
1247 (defmacro gnus-with-article-headers (&rest forms)
1249 (set-buffer gnus-article-buffer)
1251 (let ((buffer-read-only nil)
1252 (inhibit-point-motion-hooks t)
1253 (case-fold-search t))
1254 (article-narrow-to-head)
1257 (put 'gnus-with-article-headers 'lisp-indent-function 0)
1258 (put 'gnus-with-article-headers 'edebug-form-spec '(body))
1260 (defun gnus-article-goto-header (header)
1261 "Go to HEADER, which is a regular expression."
1262 (re-search-forward (concat "^\\(" header "\\):") nil t))
1264 (defsubst gnus-article-hide-text (b e props)
1265 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
1266 (gnus-add-text-properties-when 'article-type nil b e props)
1267 (when (memq 'intangible props)
1269 (max (1- b) (point-min))
1270 b 'intangible (cddr (memq 'intangible props)))))
1272 (defsubst gnus-article-unhide-text (b e)
1273 "Remove hidden text properties from region between B and E."
1274 (remove-text-properties b e gnus-hidden-properties)
1275 (when (memq 'intangible gnus-hidden-properties)
1276 (put-text-property (max (1- b) (point-min))
1277 b 'intangible nil)))
1279 (defun gnus-article-hide-text-type (b e type)
1280 "Hide text of TYPE between B and E."
1281 (push type gnus-article-wash-types)
1282 (gnus-article-hide-text
1283 b e (cons 'article-type (cons type gnus-hidden-properties))))
1285 (defun gnus-article-unhide-text-type (b e type)
1286 "Unhide text of TYPE between B and E."
1287 (setq gnus-article-wash-types
1288 (delq type gnus-article-wash-types))
1289 (remove-text-properties
1290 b e (cons 'article-type (cons type gnus-hidden-properties)))
1291 (when (memq 'intangible gnus-hidden-properties)
1292 (put-text-property (max (1- b) (point-min))
1293 b 'intangible nil)))
1295 (defun gnus-article-hide-text-of-type (type)
1296 "Hide text of TYPE in the current buffer."
1298 (let ((b (point-min))
1300 (while (setq b (text-property-any b e 'article-type type))
1301 (add-text-properties b (incf b) gnus-hidden-properties)))))
1303 (defun gnus-article-delete-text-of-type (type)
1304 "Delete text of TYPE in the current buffer."
1306 (let ((b (point-min)))
1307 (while (setq b (text-property-any b (point-max) 'article-type type))
1309 b (or (text-property-not-all b (point-max) 'article-type type)
1312 (defun gnus-article-delete-invisible-text ()
1313 "Delete all invisible text in the current buffer."
1315 (let ((b (point-min)))
1316 (while (setq b (text-property-any b (point-max) 'invisible t))
1318 b (or (text-property-not-all b (point-max) 'invisible t)
1321 (defun gnus-article-text-type-exists-p (type)
1322 "Say whether any text of type TYPE exists in the buffer."
1323 (text-property-any (point-min) (point-max) 'article-type type))
1325 (defsubst gnus-article-header-rank ()
1326 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1327 (let ((list gnus-sorted-header-list)
1330 (when (looking-at (car list))
1332 (setq list (cdr list))
1336 (defun article-hide-headers (&optional arg delete)
1337 "Hide unwanted headers and possibly sort them as well."
1339 ;; This function might be inhibited.
1340 (unless gnus-inhibit-hiding
1343 (let ((buffer-read-only nil)
1344 (case-fold-search t)
1345 (max (1+ (length gnus-sorted-header-list)))
1346 (ignored (when (not gnus-visible-headers)
1347 (cond ((stringp gnus-ignored-headers)
1348 gnus-ignored-headers)
1349 ((listp gnus-ignored-headers)
1350 (mapconcat 'identity gnus-ignored-headers
1353 (cond ((stringp gnus-visible-headers)
1354 gnus-visible-headers)
1355 ((and gnus-visible-headers
1356 (listp gnus-visible-headers))
1357 (mapconcat 'identity gnus-visible-headers "\\|"))))
1358 (inhibit-point-motion-hooks t)
1360 ;; First we narrow to just the headers.
1361 (article-narrow-to-head)
1362 ;; Hide any "From " lines at the beginning of (mail) articles.
1363 (while (looking-at "From ")
1366 (delete-region (point-min) (point)))
1367 ;; Then treat the rest of the header lines.
1368 ;; Then we use the two regular expressions
1369 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1370 ;; select which header lines is to remain visible in the
1372 (while (re-search-forward "^[^ \t:]*:" nil t)
1374 ;; Mark the rank of the header.
1376 (point) (1+ (point)) 'message-rank
1377 (if (or (and visible (looking-at visible))
1379 (not (looking-at ignored))))
1380 (gnus-article-header-rank)
1383 (message-sort-headers-1)
1384 (when (setq beg (text-property-any
1385 (point-min) (point-max) 'message-rank (+ 2 max)))
1386 ;; We delete the unwanted headers.
1387 (push 'headers gnus-article-wash-types)
1388 (add-text-properties (point-min) (+ 5 (point-min))
1389 '(article-type headers dummy-invisible t))
1390 (delete-region beg (point-max))))))))
1392 (defun article-hide-boring-headers (&optional arg)
1393 "Toggle hiding of headers that aren't very interesting.
1394 If given a negative prefix, always show; if given a positive prefix,
1396 (interactive (gnus-article-hidden-arg))
1397 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1398 (not gnus-show-all-headers))
1401 (let ((buffer-read-only nil)
1402 (list gnus-boring-article-headers)
1403 (inhibit-point-motion-hooks t)
1405 (article-narrow-to-head)
1407 (setq elem (pop list))
1408 (goto-char (point-min))
1410 ;; Hide empty headers.
1412 (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1414 (gnus-article-hide-text-type
1415 (progn (beginning-of-line) (point))
1418 (if (re-search-forward "^[^ \t]" nil t)
1422 ;; Hide boring Newsgroups header.
1423 ((eq elem 'newsgroups)
1424 (when (gnus-string-equal
1425 (gnus-fetch-field "newsgroups")
1426 (gnus-group-real-name
1427 (if (boundp 'gnus-newsgroup-name)
1430 (gnus-article-hide-header "newsgroups")))
1431 ((eq elem 'to-address)
1432 (let ((to (message-fetch-field "to"))
1434 (gnus-parameter-to-address
1435 (if (boundp 'gnus-newsgroup-name)
1436 gnus-newsgroup-name ""))))
1437 (when (and to to-address
1440 ;; only one address in To
1441 (nth 1 (mail-extract-address-components to))
1443 (gnus-article-hide-header "to"))))
1444 ((eq elem 'followup-to)
1445 (when (gnus-string-equal
1446 (message-fetch-field "followup-to")
1447 (message-fetch-field "newsgroups"))
1448 (gnus-article-hide-header "followup-to")))
1449 ((eq elem 'reply-to)
1450 (let ((from (message-fetch-field "from"))
1451 (reply-to (message-fetch-field "reply-to")))
1456 (nth 1 (mail-extract-address-components from))
1457 (nth 1 (mail-extract-address-components reply-to)))))
1458 (gnus-article-hide-header "reply-to"))))
1460 (let ((date (message-fetch-field "date")))
1462 (< (days-between (current-time-string) date)
1464 (gnus-article-hide-header "date"))))
1466 (let ((to (message-fetch-field "to"))
1467 (cc (message-fetch-field "cc")))
1468 (when (> (length to) 1024)
1469 (gnus-article-hide-header "to"))
1470 (when (> (length cc) 1024)
1471 (gnus-article-hide-header "cc"))))
1475 (goto-char (point-min))
1476 (while (re-search-forward "^to:" nil t)
1477 (setq to-count (1+ to-count)))
1478 (when (> to-count 1)
1479 (while (> to-count 0)
1480 (goto-char (point-min))
1482 (re-search-forward "^to:" nil nil to-count)
1484 (narrow-to-region (point) (point-max))
1485 (gnus-article-hide-header "to"))
1486 (setq to-count (1- to-count))))
1487 (goto-char (point-min))
1488 (while (re-search-forward "^cc:" nil t)
1489 (setq cc-count (1+ cc-count)))
1490 (when (> cc-count 1)
1491 (while (> cc-count 0)
1492 (goto-char (point-min))
1494 (re-search-forward "^cc:" nil nil cc-count)
1496 (narrow-to-region (point) (point-max))
1497 (gnus-article-hide-header "cc"))
1498 (setq cc-count (1- cc-count)))))))))))))
1500 (defun gnus-article-hide-header (header)
1502 (goto-char (point-min))
1503 (when (re-search-forward (concat "^" header ":") nil t)
1504 (gnus-article-hide-text-type
1505 (progn (beginning-of-line) (point))
1508 (if (re-search-forward "^[^ \t]" nil t)
1513 (defvar gnus-article-normalized-header-length 40
1514 "Length of normalized headers.")
1516 (defun article-normalize-headers ()
1517 "Make all header lines 40 characters long."
1519 (let ((buffer-read-only nil)
1523 (article-narrow-to-head)
1526 ((< (setq column (- (gnus-point-at-eol) (point)))
1527 gnus-article-normalized-header-length)
1529 (insert (make-string
1530 (- gnus-article-normalized-header-length column)
1532 ((> column gnus-article-normalized-header-length)
1533 (gnus-put-text-property
1535 (forward-char gnus-article-normalized-header-length)
1542 (forward-line 1))))))
1544 (defun article-treat-dumbquotes ()
1545 "Translate M****s*** sm*rtq**t*s into proper text.
1546 Note that this function guesses whether a character is a sm*rtq**t* or
1547 not, so it should only be used interactively.
1549 Sm*rtq**t*s are M****s***'s unilateral extension to the character map
1550 in an attempt to provide more quoting characters. If you see
1551 something like \\222 or \\264 where you're expecting some kind of
1552 apostrophe or quotation mark, then try this wash."
1554 (article-translate-strings gnus-article-dumbquotes-map))
1556 (defun article-translate-characters (from to)
1557 "Translate all characters in the body of the article according to FROM and TO.
1558 FROM is a string of characters to translate from; to is a string of
1559 characters to translate to."
1561 (when (article-goto-body)
1562 (let ((buffer-read-only nil)
1563 (x (make-string 225 ?x))
1565 (while (< (incf i) (length x))
1568 (while (< i (length from))
1569 (aset x (aref from i) (aref to i))
1571 (translate-region (point) (point-max) x)))))
1573 (defun article-translate-strings (map)
1574 "Translate all string in the body of the article according to MAP.
1575 MAP is an alist where the elements are on the form (\"from\" \"to\")."
1577 (when (article-goto-body)
1578 (let ((buffer-read-only nil)
1580 (while (setq elem (pop map))
1582 (while (search-forward (car elem) nil t)
1583 (replace-match (cadr elem)))))))))
1585 (defun article-treat-overstrike ()
1586 "Translate overstrikes into bold text."
1589 (when (article-goto-body)
1590 (let ((buffer-read-only nil))
1591 (while (search-forward "\b" nil t)
1592 (let ((next (char-after))
1593 (previous (char-after (- (point) 2))))
1594 ;; We do the boldification/underlining by hiding the
1595 ;; overstrikes and putting the proper text property
1599 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
1600 (put-text-property (point) (1+ (point)) 'face 'bold))
1602 (gnus-article-hide-text-type
1603 (1- (point)) (1+ (point)) 'overstrike)
1605 (- (point) 2) (1- (point)) 'face 'underline))
1607 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
1609 (point) (1+ (point)) 'face 'underline)))))))))
1611 (defun gnus-article-treat-unfold-headers ()
1612 "Unfold folded message headers.
1613 Only the headers that fit into the current window width will be
1616 (gnus-with-article-headers
1620 (mail-header-narrow-to-field)
1621 (let ((header (buffer-substring (point-min) (point-max))))
1624 (goto-char (point-min))
1625 (while (re-search-forward "[\t ]*\n[\t ]+" nil t)
1626 (replace-match " " t t)))
1627 (setq length (- (point-max) (point-min) 1)))
1628 (when (< length (window-width))
1629 (while (re-search-forward "[\t ]*\n[\t ]+" nil t)
1630 (replace-match " " t t)))
1631 (goto-char (point-max)))))))
1633 (defun gnus-article-treat-fold-newsgroups ()
1634 "Unfold folded message headers.
1635 Only the headers that fit into the current window width will be
1638 (gnus-with-article-headers
1639 (while (gnus-article-goto-header "newsgroups\\|followup-to")
1641 (mail-header-narrow-to-field)
1642 (while (search-forward "," nil t)
1643 (replace-match ", " t t))
1644 (mail-header-fold-field)
1645 (goto-char (point-max))))))
1647 (defun gnus-article-treat-body-boundary ()
1648 "Place a boundary line at the end of the headers."
1650 (gnus-with-article-headers
1651 (goto-char (point-max))
1652 (let ((start (point)))
1653 (insert "X-Boundary: ")
1654 (gnus-add-text-properties start (point) '(invisible t intangible t))
1655 (insert (make-string (1- (window-width)) ?-)
1658 (defun article-fill-long-lines ()
1659 "Fill lines that are wider than the window width."
1662 (let ((buffer-read-only nil)
1663 (width (window-width (get-buffer-window (current-buffer)))))
1666 (let ((adaptive-fill-mode nil)) ;Why? -sm
1669 (when (>= (current-column) (min fill-column width))
1670 (narrow-to-region (point) (gnus-point-at-bol))
1671 (fill-paragraph nil)
1672 (goto-char (point-max))
1674 (forward-line 1)))))))
1676 (defun article-capitalize-sentences ()
1677 "Capitalize the first word in each sentence."
1680 (let ((buffer-read-only nil)
1681 (paragraph-start "^[\n\^L]"))
1685 (forward-sentence)))))
1687 (defun article-remove-cr ()
1688 "Remove trailing CRs and then translate remaining CRs into LFs."
1691 (let ((buffer-read-only nil))
1692 (goto-char (point-min))
1693 (while (re-search-forward "\r+$" nil t)
1694 (replace-match "" t t))
1695 (goto-char (point-min))
1696 (while (search-forward "\r" nil t)
1697 (replace-match "\n" t t)))))
1699 (defun article-remove-trailing-blank-lines ()
1700 "Remove all trailing blank lines from the article."
1703 (let ((buffer-read-only nil))
1704 (goto-char (point-max))
1708 (while (and (not (bobp))
1709 (looking-at "^[ \t]*$")
1710 (not (gnus-annotation-in-region-p
1711 (point) (gnus-point-at-eol))))
1716 (defun article-display-x-face (&optional force)
1717 "Look for an X-Face header and display it if present."
1718 (interactive (list 'force))
1720 ;; Delete the old process, if any.
1721 (when (process-status "article-x-face")
1722 (delete-process "article-x-face"))
1723 (let ((inhibit-point-motion-hooks t)
1725 (case-fold-search t)
1728 (article-narrow-to-head)
1729 (when (and buffer-read-only ;; When type `W f'
1731 (goto-char (point-min))
1732 (not (re-search-forward "^X-Face:[\t ]*" nil t)))
1733 (gnus-buffer-live-p gnus-original-article-buffer))
1734 (with-current-buffer gnus-original-article-buffer
1736 (article-narrow-to-head)
1737 (while (re-search-forward "^X-Face:" nil t)
1743 (1- (re-search-forward
1744 "^\\($\\|[^ \t]\\)" nil t))))))))
1746 (let (point start bface eface buffer-read-only)
1747 (goto-char (point-max))
1749 (setq bface (get-text-property (gnus-point-at-bol) 'face)
1750 eface (get-text-property (1- (gnus-point-at-eol)) 'face))
1751 (goto-char (point-max))
1752 (setq point (point))
1755 (while (looking-at "\\([^:]+\\): *")
1756 (put-text-property (match-beginning 1) (1+ (match-end 1))
1758 (setq start (match-end 0))
1760 (while (looking-at "[\t ]")
1762 (put-text-property start (point)
1764 (goto-char (point-min))
1765 (setq from (message-fetch-field "from"))
1766 (goto-char (point-min))
1767 (while (and gnus-article-x-face-command
1770 ;; Check whether this face is censored.
1771 (not gnus-article-x-face-too-ugly)
1772 (and gnus-article-x-face-too-ugly from
1773 (not (string-match gnus-article-x-face-too-ugly
1775 ;; Has to be present.
1776 (re-search-forward "^X-Face:[\t ]*" nil t))
1777 ;; This used to try to do multiple faces (`while' instead of
1778 ;; `when' above), but (a) sending multiple EOFs to xv doesn't
1779 ;; work (b) it can crash some versions of Emacs (c) are
1780 ;; multiple faces really something to encourage?
1781 (when (stringp gnus-article-x-face-command)
1783 ;; We now have the area of the buffer where the X-Face is stored.
1786 (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t)))
1788 ;; We display the face.
1789 (if (symbolp gnus-article-x-face-command)
1790 ;; The command is a lisp function, so we call it.
1791 (if (gnus-functionp gnus-article-x-face-command)
1792 (funcall gnus-article-x-face-command beg end)
1793 (error "%s is not a function" gnus-article-x-face-command))
1794 ;; The command is a string, so we interpret the command
1795 ;; as a, well, command, and fork it off.
1796 (let ((process-connection-type nil))
1797 (process-kill-without-query
1799 "article-x-face" nil shell-file-name shell-command-switch
1800 gnus-article-x-face-command))
1801 (process-send-region "article-x-face" beg end)
1802 (process-send-eof "article-x-face"))))))))))
1804 (defun article-decode-mime-words ()
1805 "Decode all MIME-encoded words in the article."
1808 (set-buffer gnus-article-buffer)
1809 (let ((inhibit-point-motion-hooks t)
1811 (mail-parse-charset gnus-newsgroup-charset)
1812 (mail-parse-ignored-charsets
1813 (save-excursion (set-buffer gnus-summary-buffer)
1814 gnus-newsgroup-ignored-charsets)))
1815 (mail-decode-encoded-word-region (point-min) (point-max)))))
1817 (defun article-decode-charset (&optional prompt)
1818 "Decode charset-encoded text in the article.
1819 If PROMPT (the prefix), prompt for a coding system to use."
1821 (let ((inhibit-point-motion-hooks t) (case-fold-search t)
1823 (mail-parse-charset gnus-newsgroup-charset)
1824 (mail-parse-ignored-charsets
1825 (save-excursion (condition-case nil
1826 (set-buffer gnus-summary-buffer)
1828 gnus-newsgroup-ignored-charsets))
1829 ct cte ctl charset format)
1832 (article-narrow-to-head)
1833 (setq ct (message-fetch-field "Content-Type" t)
1834 cte (message-fetch-field "Content-Transfer-Encoding" t)
1835 ctl (and ct (ignore-errors
1836 (mail-header-parse-content-type ct)))
1839 (mm-read-coding-system "Charset to decode: "))
1841 (mail-content-type-get ctl 'charset)))
1842 format (and ctl (mail-content-type-get ctl 'format)))
1844 (setq cte (mail-header-strip cte)))
1845 (if (and ctl (not (string-match "/" (car ctl))))
1847 (goto-char (point-max)))
1850 (narrow-to-region (point) (point-max))
1851 (when (and (eq mail-parse-charset 'gnus-decoded)
1852 (eq (mm-body-7-or-8) '8bit))
1853 ;; The text code could have been decoded.
1854 (setq charset mail-parse-charset))
1855 (when (and (or (not ctl)
1856 (equal (car ctl) "text/plain"))
1857 (not format)) ;; article with format will decode later.
1859 charset (and cte (intern (downcase
1860 (gnus-strip-whitespace cte))))
1863 (defun article-decode-encoded-words ()
1864 "Remove encoded-word encoding from headers."
1865 (let ((inhibit-point-motion-hooks t)
1866 (mail-parse-charset gnus-newsgroup-charset)
1867 (mail-parse-ignored-charsets
1868 (save-excursion (condition-case nil
1869 (set-buffer gnus-summary-buffer)
1871 gnus-newsgroup-ignored-charsets))
1874 (article-narrow-to-head)
1875 (funcall gnus-decode-header-function (point-min) (point-max)))))
1877 (defun article-decode-group-name ()
1878 "Decode group names in `Newsgroups:'."
1879 (let ((inhibit-point-motion-hooks t)
1881 (method (gnus-find-method-for-group gnus-newsgroup-name)))
1882 (when (and (or gnus-group-name-charset-method-alist
1883 gnus-group-name-charset-group-alist)
1884 (gnus-buffer-live-p gnus-original-article-buffer))
1885 (when (nnmail-fetch-field "Newsgroups")
1886 (nnheader-replace-header "Newsgroups"
1887 (gnus-decode-newsgroups
1888 (with-current-buffer
1889 gnus-original-article-buffer
1890 (nnmail-fetch-field "Newsgroups"))
1891 gnus-newsgroup-name method)))
1892 (when (nnmail-fetch-field "Followup-To")
1893 (nnheader-replace-header "Followup-To"
1894 (gnus-decode-newsgroups
1895 (with-current-buffer
1896 gnus-original-article-buffer
1897 (nnmail-fetch-field "Followup-To"))
1898 gnus-newsgroup-name method))))))
1900 (defun article-de-quoted-unreadable (&optional force read-charset)
1901 "Translate a quoted-printable-encoded article.
1902 If FORCE, decode the article whether it is marked as quoted-printable
1904 If READ-CHARSET, ask for a coding system."
1905 (interactive (list 'force current-prefix-arg))
1907 (let ((buffer-read-only nil) type charset)
1908 (if (gnus-buffer-live-p gnus-original-article-buffer)
1909 (with-current-buffer gnus-original-article-buffer
1911 (gnus-fetch-field "content-transfer-encoding"))
1912 (let* ((ct (gnus-fetch-field "content-type"))
1915 (mail-header-parse-content-type ct)))))
1916 (setq charset (and ctl
1917 (mail-content-type-get ctl 'charset)))
1918 (if (stringp charset)
1919 (setq charset (intern (downcase charset)))))))
1921 (setq charset (mm-read-coding-system "Charset: " charset)))
1923 (setq charset gnus-newsgroup-charset))
1925 (and type (let ((case-fold-search t))
1926 (string-match "quoted-printable" type))))
1928 (quoted-printable-decode-region
1929 (point) (point-max) (mm-charset-to-coding-system charset))))))
1931 (defun article-de-base64-unreadable (&optional force read-charset)
1932 "Translate a base64 article.
1933 If FORCE, decode the article whether it is marked as base64 not.
1934 If READ-CHARSET, ask for a coding system."
1935 (interactive (list 'force current-prefix-arg))
1937 (let ((buffer-read-only nil) type charset)
1938 (if (gnus-buffer-live-p gnus-original-article-buffer)
1939 (with-current-buffer gnus-original-article-buffer
1941 (gnus-fetch-field "content-transfer-encoding"))
1942 (let* ((ct (gnus-fetch-field "content-type"))
1945 (mail-header-parse-content-type ct)))))
1946 (setq charset (and ctl
1947 (mail-content-type-get ctl 'charset)))
1948 (if (stringp charset)
1949 (setq charset (intern (downcase charset)))))))
1951 (setq charset (mm-read-coding-system "Charset: " charset)))
1953 (setq charset gnus-newsgroup-charset))
1955 (and type (let ((case-fold-search t))
1956 (string-match "base64" type))))
1959 (narrow-to-region (point) (point-max))
1960 (base64-decode-region (point-min) (point-max))
1961 (mm-decode-coding-region
1962 (point-min) (point-max) (mm-charset-to-coding-system charset)))))))
1967 (defun article-decode-HZ ()
1968 "Translate a HZ-encoded article."
1972 (let ((buffer-read-only nil))
1973 (rfc1843-decode-region (point-min) (point-max)))))
1975 (defun article-wash-html (&optional read-charset)
1976 "Format an html article.
1977 If READ-CHARSET, ask for a coding system."
1980 (let ((buffer-read-only nil)
1982 (if (gnus-buffer-live-p gnus-original-article-buffer)
1983 (with-current-buffer gnus-original-article-buffer
1984 (let* ((ct (gnus-fetch-field "content-type"))
1987 (mail-header-parse-content-type ct)))))
1988 (setq charset (and ctl
1989 (mail-content-type-get ctl 'charset)))
1990 (if (stringp charset)
1991 (setq charset (intern (downcase charset)))))))
1993 (setq charset (mm-read-coding-system "Charset: " charset)))
1995 (setq charset gnus-newsgroup-charset))
1997 (save-window-excursion
1999 (narrow-to-region (point) (point-max))
2001 (let ((w3-strict-width (window-width))
2002 (url-standalone-mode t)
2003 (w3-honor-stylesheets nil)
2004 (w3-delay-image-loads t))
2006 (w3-region (point-min) (point-max))
2009 (defun article-hide-list-identifiers ()
2010 "Remove list identifies from the Subject header.
2011 The `gnus-list-identifiers' variable specifies what to do."
2013 (let ((inhibit-point-motion-hooks t)
2014 (regexp (if (consp gnus-list-identifiers)
2015 (mapconcat 'identity gnus-list-identifiers " *\\|")
2016 gnus-list-identifiers))
2021 (article-narrow-to-head)
2022 (goto-char (point-min))
2023 (while (re-search-forward
2024 (concat "^Subject: +\\(R[Ee]: +\\)*\\(" regexp " *\\)")
2026 (delete-region (match-beginning 2) (match-end 0))
2027 (beginning-of-line))
2028 (when (re-search-forward
2029 "^Subject: +\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" nil t)
2030 (delete-region (match-beginning 1) (match-end 1))))))))
2032 (defun article-hide-pgp ()
2033 "Remove any PGP headers and signatures in the current article."
2037 (let ((inhibit-point-motion-hooks t)
2038 buffer-read-only beg end)
2040 ;; Hide the "header".
2041 (when (re-search-forward "^-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
2042 (push 'pgp gnus-article-wash-types)
2043 (delete-region (match-beginning 0) (match-end 0))
2044 ;; Remove armor headers (rfc2440 6.2)
2045 (delete-region (point) (or (re-search-forward "^[ \t]*\n" nil t)
2048 ;; Hide the actual signature.
2049 (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
2050 (setq end (1+ (match-beginning 0)))
2053 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
2055 ;; Perhaps we shouldn't hide to the end of the buffer
2056 ;; if there is no end to the signature?
2058 ;; Hide "- " PGP quotation markers.
2060 (narrow-to-region beg end)
2061 (goto-char (point-min))
2062 (while (re-search-forward "^- " nil t)
2064 (match-beginning 0) (match-end 0)))
2066 (gnus-run-hooks 'gnus-article-hide-pgp-hook))))))
2068 (defun article-hide-pem (&optional arg)
2069 "Toggle hiding of any PEM headers and signatures in the current article.
2070 If given a negative prefix, always show; if given a positive prefix,
2072 (interactive (gnus-article-hidden-arg))
2073 (unless (gnus-article-check-hidden-text 'pem arg)
2075 (let (buffer-read-only end)
2076 (goto-char (point-min))
2077 ;; Hide the horrendously ugly "header".
2078 (when (and (search-forward
2079 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
2081 (setq end (1+ (match-beginning 0))))
2082 (push 'pem gnus-article-wash-types)
2083 (gnus-article-hide-text-type
2085 (if (search-forward "\n\n" nil t)
2089 ;; Hide the trailer as well
2090 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
2092 (gnus-article-hide-text-type
2093 (match-beginning 0) (match-end 0) 'pem)))))))
2095 (defun article-strip-banner ()
2096 "Strip the banner specified by the `banner' group parameter."
2100 (let ((inhibit-point-motion-hooks t)
2101 (banner (gnus-parameter-banner gnus-newsgroup-name))
2102 (gnus-signature-limit nil)
2103 buffer-read-only beg end)
2107 ((eq banner 'signature)
2108 (when (gnus-article-narrow-to-signature)
2111 (delete-region (point) (point-max))))
2113 (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
2114 (while (re-search-forward banner nil t)
2115 (delete-region (match-beginning 0) (match-end 0)))))
2117 (while (re-search-forward banner nil t)
2118 (delete-region (match-beginning 0) (match-end 0))))))))))
2120 (defun article-babel ()
2121 "Translate article using an online translation service."
2125 (set-buffer gnus-article-buffer)
2126 (when (article-goto-body)
2127 (let* ((buffer-read-only nil)
2130 (orig (buffer-substring start end))
2131 (trans (babel-as-string orig)))
2133 (narrow-to-region start end)
2134 (delete-region start end)
2137 (defun article-hide-signature (&optional arg)
2138 "Hide the signature in the current article.
2139 If given a negative prefix, always show; if given a positive prefix,
2141 (interactive (gnus-article-hidden-arg))
2142 (unless (gnus-article-check-hidden-text 'signature arg)
2145 (let ((buffer-read-only nil))
2146 (when (gnus-article-narrow-to-signature)
2147 (gnus-article-hide-text-type
2148 (point-min) (point-max) 'signature))))))
2149 (gnus-set-mode-line 'article))
2151 (defun article-strip-headers-in-body ()
2152 "Strip offensive headers from bodies."
2156 (let ((case-fold-search t))
2157 (when (looking-at "x-no-archive:")
2158 (gnus-delete-line)))))
2160 (defun article-strip-leading-blank-lines ()
2161 "Remove all blank lines from the beginning of the article."
2164 (let ((inhibit-point-motion-hooks t)
2166 (when (article-goto-body)
2167 (while (and (not (eobp))
2168 (looking-at "[ \t]*$"))
2169 (gnus-delete-line))))))
2171 (defun article-narrow-to-head ()
2172 "Narrow the buffer to the head of the message.
2173 Point is left at the beginning of the narrowed-to region."
2175 (goto-char (point-min))
2176 (if (search-forward "\n\n" nil 1)
2179 (goto-char (point-min)))
2181 (defun article-goto-body ()
2182 "Place point at the start of the body."
2183 (goto-char (point-min))
2185 ;; This variable is only bound when dealing with separate
2187 (article-goto-body-goes-to-point-min-p
2189 ((search-forward "\n\n" nil t)
2192 (goto-char (point-max))
2195 (defun article-strip-multiple-blank-lines ()
2196 "Replace consecutive blank lines with one empty line."
2199 (let ((inhibit-point-motion-hooks t)
2201 ;; First make all blank lines empty.
2203 (while (re-search-forward "^[ \t]+$" nil t)
2204 (unless (gnus-annotation-in-region-p
2205 (match-beginning 0) (match-end 0))
2206 (replace-match "" nil t)))
2207 ;; Then replace multiple empty lines with a single empty line.
2209 (while (re-search-forward "\n\n\\(\n+\\)" nil t)
2210 (unless (gnus-annotation-in-region-p
2211 (match-beginning 0) (match-end 0))
2212 (delete-region (match-beginning 1) (match-end 1)))))))
2214 (defun article-strip-leading-space ()
2215 "Remove all white space from the beginning of the lines in the article."
2218 (let ((inhibit-point-motion-hooks t)
2221 (while (re-search-forward "^[ \t]+" nil t)
2222 (replace-match "" t t)))))
2224 (defun article-strip-trailing-space ()
2225 "Remove all white space from the end of the lines in the article."
2228 (let ((inhibit-point-motion-hooks t)
2231 (while (re-search-forward "[ \t]+$" nil t)
2232 (replace-match "" t t)))))
2234 (defun article-strip-blank-lines ()
2235 "Strip leading, trailing and multiple blank lines."
2237 (article-strip-leading-blank-lines)
2238 (article-remove-trailing-blank-lines)
2239 (article-strip-multiple-blank-lines))
2241 (defun article-strip-all-blank-lines ()
2242 "Strip all blank lines."
2245 (let ((inhibit-point-motion-hooks t)
2248 (while (re-search-forward "^[ \t]*\n" nil t)
2249 (replace-match "" t t)))))
2251 (defun gnus-article-narrow-to-signature ()
2252 "Narrow to the signature; return t if a signature is found, else nil."
2253 (let ((inhibit-point-motion-hooks t))
2254 (when (gnus-article-search-signature)
2256 ;; Check whether we have some limits to what we consider
2257 ;; to be a signature.
2258 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
2259 (list gnus-signature-limit)))
2261 (while (setq limit (pop limits))
2262 (if (or (and (integerp limit)
2263 (< (- (point-max) (point)) limit))
2265 (< (count-lines (point) (point-max)) limit))
2266 (and (gnus-functionp limit)
2268 (and (stringp limit)
2269 (not (re-search-forward limit nil t))))
2270 () ; This limit did not succeed.
2274 (narrow-to-region (point) (point-max))
2277 (defun gnus-article-search-signature ()
2278 "Search the current buffer for the signature separator.
2279 Put point at the beginning of the signature separator."
2280 (let ((cur (point)))
2281 (goto-char (point-max))
2282 (if (if (stringp gnus-signature-separator)
2283 (re-search-backward gnus-signature-separator nil t)
2284 (let ((seps gnus-signature-separator))
2286 (not (re-search-backward (car seps) nil t)))
2293 (defun gnus-article-hidden-arg ()
2294 "Return the current prefix arg as a number, or 0 if no prefix."
2295 (list (if current-prefix-arg
2296 (prefix-numeric-value current-prefix-arg)
2299 (defun gnus-article-check-hidden-text (type arg)
2300 "Return nil if hiding is necessary.
2301 Arg can be nil or a number. nil and positive means hide, negative
2302 means show, 0 means toggle."
2305 (let ((hide (gnus-article-hidden-text-p type)))
2311 (gnus-article-show-hidden-text type)
2314 (if (eq hide 'hidden)
2316 (gnus-article-show-hidden-text type)
2320 (defun gnus-article-hidden-text-p (type)
2321 "Say whether the current buffer contains hidden text of type TYPE."
2322 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
2324 (not (get-text-property pos 'invisible))
2325 (not (get-text-property pos 'dummy-invisible)))
2327 (text-property-any (1+ pos) (point-max) 'article-type type)))
2332 (defun gnus-article-show-hidden-text (type &optional dummy)
2333 "Show all hidden text of type TYPE.
2334 Originally it is hide instead of DUMMY."
2335 (let ((buffer-read-only nil)
2336 (inhibit-point-motion-hooks t))
2337 (gnus-remove-text-properties-when
2339 (point-min) (point-max)
2340 (cons 'article-type (cons type
2341 gnus-hidden-properties)))
2342 (setq gnus-article-wash-types (delq type gnus-article-wash-types))))
2344 (defconst article-time-units
2345 `((year . ,(* 365.25 24 60 60))
2346 (week . ,(* 7 24 60 60))
2347 (day . ,(* 24 60 60))
2351 "Mapping from time units to seconds.")
2353 (defun article-date-ut (&optional type highlight header)
2354 "Convert DATE date to universal time in the current article.
2355 If TYPE is `local', convert to local time; if it is `lapsed', output
2356 how much time has lapsed since DATE. For `lapsed', the value of
2357 `gnus-article-date-lapsed-new-header' says whether the \"X-Sent:\" header
2358 should replace the \"Date:\" one, or should be added below it."
2359 (interactive (list 'ut t))
2360 (let* ((header (or header
2361 (message-fetch-field "date")
2363 (tdate-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
2366 ((not gnus-article-date-lapsed-new-header)
2372 (date (if (vectorp header) (mail-header-date header)
2374 (inhibit-point-motion-hooks t)
2379 (article-narrow-to-head)
2380 (when (re-search-forward tdate-regexp nil t)
2381 (setq bface (get-text-property (gnus-point-at-bol) 'face)
2382 date (or (get-text-property (gnus-point-at-bol)
2385 eface (get-text-property (1- (gnus-point-at-eol)) 'face))
2387 (when (and date (not (string= date "")))
2388 (goto-char (point-min))
2389 (let ((buffer-read-only nil))
2390 ;; Delete any old Date headers.
2391 (while (re-search-forward date-regexp nil t)
2393 (delete-region (progn (beginning-of-line) (point))
2394 (progn (forward-line 1) (point)))
2395 (delete-region (progn (beginning-of-line) (point))
2396 (progn (end-of-line) (point)))
2397 (setq pos (point))))
2398 (when (and (not pos) (re-search-forward tdate-regexp nil t))
2400 (if pos (goto-char pos))
2401 (insert (article-make-date-line date (or type 'ut)))
2407 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
2408 (put-text-property (match-beginning 1) (1+ (match-end 1))
2409 'original-date date)
2410 (put-text-property (match-beginning 1) (1+ (match-end 1))
2412 (put-text-property (match-beginning 2) (match-end 2)
2415 (defun article-make-date-line (date type)
2416 "Return a DATE line of TYPE."
2417 (unless (memq type '(local ut original user iso8601 lapsed english))
2418 (error "Unknown conversion type: %s" type))
2420 (let ((time (date-to-time date)))
2422 ;; Convert to the local timezone.
2424 (let ((tz (car (current-time-zone time))))
2425 (format "Date: %s %s%02d%02d" (current-time-string time)
2426 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2427 (/ (% (abs tz) 3600) 60))))
2428 ;; Convert to Universal Time.
2431 (current-time-string
2432 (let* ((e (parse-time-string date))
2433 (tm (apply 'encode-time e))
2435 (ls (- (cadr tm) (car (current-time-zone time)))))
2436 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
2437 ((> ls 65535) (list (1+ ms) (- ls 65536)))
2440 ;; Get the original date from the article.
2441 ((eq type 'original)
2442 (concat "Date: " (if (string-match "\n+$" date)
2443 (substring date 0 (match-beginning 0))
2445 ;; Let the user define the format.
2447 (if (gnus-functionp gnus-article-time-format)
2448 (funcall gnus-article-time-format time)
2451 (format-time-string gnus-article-time-format time))))
2454 (let ((tz (car (current-time-zone time))))
2457 (format-time-string "%Y%m%dT%H%M%S" time)
2458 (format "%s%02d%02d"
2459 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2460 (/ (% (abs tz) 3600) 60)))))
2461 ;; Do an X-Sent lapsed format.
2463 ;; If the date is seriously mangled, the timezone functions are
2464 ;; liable to bug out, so we ignore all errors.
2465 (let* ((now (current-time))
2466 (real-time (subtract-time now time))
2467 (real-sec (and real-time
2468 (+ (* (float (car real-time)) 65536)
2470 (sec (and real-time (abs real-sec)))
2480 ;; This is a bit convoluted, but basically we go
2481 ;; through the time units for years, weeks, etc,
2482 ;; and divide things to see whether that results
2483 ;; in positive answers.
2486 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
2487 ;; The (remaining) seconds are too few to
2488 ;; be divided into this time unit.
2490 ;; It's big enough, so we output it.
2491 (setq sec (- sec (* num (cdr unit))))
2493 (concat (if prev ", " "") (int-to-string
2495 " " (symbol-name (car unit))
2496 (if (> num 1) "s" ""))
2498 article-time-units "")
2499 ;; If dates are odd, then it might appear like the
2500 ;; article was sent in the future.
2503 " in the future"))))))
2504 ;; Display the date in proper English
2506 (let ((dtime (decode-time time)))
2509 (number-to-string (nth 3 dtime))
2510 (let ((digit (% (nth 3 dtime) 10)))
2512 ((memq (nth 3 dtime) '(11 12 13)) "th")
2518 (nth (1- (nth 4 dtime)) gnus-english-month-names)
2520 (number-to-string (nth 5 dtime))
2522 (format "%02d" (nth 2 dtime))
2524 (format "%02d" (nth 1 dtime)))))))
2526 (format "Date: %s (from Oort)" date))))
2528 (defun article-date-local (&optional highlight)
2529 "Convert the current article date to the local timezone."
2530 (interactive (list t))
2531 (article-date-ut 'local highlight))
2533 (defun article-date-english (&optional highlight)
2534 "Convert the current article date to something that is proper English."
2535 (interactive (list t))
2536 (article-date-ut 'english highlight))
2538 (defun article-date-original (&optional highlight)
2539 "Convert the current article date to what it was originally.
2540 This is only useful if you have used some other date conversion
2541 function and want to see what the date was before converting."
2542 (interactive (list t))
2543 (article-date-ut 'original highlight))
2545 (defun article-date-lapsed (&optional highlight)
2546 "Convert the current article date to time lapsed since it was sent."
2547 (interactive (list t))
2548 (article-date-ut 'lapsed highlight))
2550 (defun article-update-date-lapsed ()
2551 "Function to be run from a timer to update the lapsed time line."
2552 (let (deactivate-mark)
2557 (set-buffer (window-buffer w))
2558 (when (eq major-mode 'gnus-article-mode)
2559 (goto-char (point-min))
2560 (when (re-search-forward "^X-Sent:" nil t)
2561 (article-date-lapsed t))))
2564 (defun gnus-start-date-timer (&optional n)
2565 "Start a timer to update the X-Sent header in the article buffers.
2566 The numerical prefix says how frequently (in seconds) the function
2571 (gnus-stop-date-timer)
2572 (setq article-lapsed-timer
2573 (nnheader-run-at-time 1 n 'article-update-date-lapsed)))
2575 (defun gnus-stop-date-timer ()
2576 "Stop the X-Sent timer."
2578 (when article-lapsed-timer
2579 (nnheader-cancel-timer article-lapsed-timer)
2580 (setq article-lapsed-timer nil)))
2582 (defun article-date-user (&optional highlight)
2583 "Convert the current article date to the user-defined format.
2584 This format is defined by the `gnus-article-time-format' variable."
2585 (interactive (list t))
2586 (article-date-ut 'user highlight))
2588 (defun article-date-iso8601 (&optional highlight)
2589 "Convert the current article date to ISO8601."
2590 (interactive (list t))
2591 (article-date-ut 'iso8601 highlight))
2593 (defun article-show-all ()
2594 "Show all hidden text in the article buffer."
2597 (let ((buffer-read-only nil))
2598 (gnus-article-unhide-text (point-min) (point-max)))))
2600 (defun article-remove-leading-whitespace ()
2601 "Remove excessive whitespace from all headers."
2605 (let ((buffer-read-only nil))
2606 (article-narrow-to-head)
2607 (goto-char (point-min))
2608 (while (re-search-forward "^[^ :]+: \\([ \t]+\\)" nil t)
2609 (delete-region (match-beginning 1) (match-end 1)))))))
2611 (defun article-emphasize (&optional arg)
2612 "Emphasize text according to `gnus-emphasis-alist'."
2613 (interactive (gnus-article-hidden-arg))
2614 (unless (gnus-article-check-hidden-text 'emphasis arg)
2618 (with-current-buffer gnus-summary-buffer
2619 gnus-article-emphasis-alist)
2621 gnus-emphasis-alist))
2622 (buffer-read-only nil)
2623 (props (append '(article-type emphasis)
2624 gnus-hidden-properties))
2625 regexp elem beg invisible visible face)
2628 (while (setq elem (pop alist))
2630 (setq regexp (car elem)
2631 invisible (nth 1 elem)
2632 visible (nth 2 elem)
2634 (while (re-search-forward regexp nil t)
2635 (when (and (match-beginning visible) (match-beginning invisible))
2636 (gnus-article-hide-text
2637 (match-beginning invisible) (match-end invisible) props)
2638 (gnus-article-unhide-text-type
2639 (match-beginning visible) (match-end visible) 'emphasis)
2640 (gnus-put-overlay-excluding-newlines
2641 (match-beginning visible) (match-end visible) 'face face)
2642 (push 'emphasis gnus-article-wash-types)
2643 (goto-char (match-end invisible)))))))))
2645 (defun gnus-article-setup-highlight-words (&optional highlight-words)
2646 "Setup newsgroup emphasis alist."
2647 (unless gnus-article-emphasis-alist
2648 (let ((name (and gnus-newsgroup-name
2649 (gnus-group-real-name gnus-newsgroup-name))))
2650 (make-local-variable 'gnus-article-emphasis-alist)
2651 (setq gnus-article-emphasis-alist
2653 (let ((alist gnus-group-highlight-words-alist) elem highlight)
2654 (while (setq elem (pop alist))
2655 (when (and name (string-match (car elem) name))
2657 highlight (copy-sequence (cdr elem)))))
2659 (copy-sequence highlight-words)
2660 (if gnus-newsgroup-name
2661 (copy-sequence (gnus-group-find-parameter
2662 gnus-newsgroup-name 'highlight-words t)))
2663 gnus-emphasis-alist)))))
2666 (defvar gnus-summary-article-menu)
2667 (defvar gnus-summary-post-menu))
2669 ;;; Saving functions.
2671 (defun gnus-article-save (save-buffer file &optional num)
2672 "Save the currently selected article."
2673 (unless gnus-save-all-headers
2674 ;; Remove headers according to `gnus-saved-headers'.
2675 (let ((gnus-visible-headers
2676 (or gnus-saved-headers gnus-visible-headers))
2677 (gnus-article-buffer save-buffer))
2679 (set-buffer save-buffer)
2680 (article-hide-headers 1 t))))
2681 (save-window-excursion
2682 (if (not gnus-default-article-saver)
2683 (error "No default saver is defined")
2684 ;; !!! Magic! The saving functions all save
2685 ;; `gnus-save-article-buffer' (or so they think), but we
2686 ;; bind that variable to our save-buffer.
2687 (set-buffer gnus-article-buffer)
2688 (let* ((gnus-save-article-buffer save-buffer)
2691 ((not gnus-prompt-before-saving) 'default)
2692 ((eq gnus-prompt-before-saving 'always) nil)
2694 (gnus-number-of-articles-to-be-saved
2695 (when (eq gnus-prompt-before-saving t)
2697 (set-buffer gnus-article-current-summary)
2698 (funcall gnus-default-article-saver filename)))))
2700 (defun gnus-read-save-file-name (prompt &optional filename
2701 function group headers variable)
2703 (funcall function group headers (symbol-value variable)))
2708 ((eq filename 'default)
2714 (let* ((split-name (gnus-get-split-value gnus-split-methods))
2717 (if (and gnus-number-of-articles-to-be-saved
2718 (> gnus-number-of-articles-to-be-saved 1))
2719 (format "these %d articles"
2720 gnus-number-of-articles-to-be-saved)
2723 ;; Let the split methods have their say.
2725 ;; No split name was found.
2728 (concat prompt " (default "
2729 (file-name-nondirectory default-name) ") ")
2730 (file-name-directory default-name)
2732 ;; A single group name is returned.
2733 ((stringp split-name)
2735 (funcall function split-name headers
2736 (symbol-value variable)))
2738 (concat prompt " (default "
2739 (file-name-nondirectory default-name) ") ")
2740 (file-name-directory default-name)
2742 ;; A single split name was found
2743 ((= 1 (length split-name))
2744 (let* ((name (expand-file-name
2746 gnus-article-save-directory))
2747 (dir (cond ((file-directory-p name)
2748 (file-name-as-directory name))
2749 ((file-exists-p name) name)
2750 (t gnus-article-save-directory))))
2752 (concat prompt " (default " name ") ")
2754 ;; A list of splits was found.
2756 (setq split-name (nreverse split-name))
2758 (let ((file-name-history
2759 (nconc split-name file-name-history)))
2763 (concat prompt " (`M-p' for defaults) ")
2764 gnus-article-save-directory
2766 gnus-article-save-directory)))
2767 (car (push result file-name-history)))))))
2768 ;; Create the directory.
2769 (gnus-make-directory (file-name-directory file))
2770 ;; If we have read a directory, we append the default file name.
2771 (when (file-directory-p file)
2772 (setq file (expand-file-name (file-name-nondirectory
2774 (file-name-as-directory file))))
2775 ;; Possibly translate some characters.
2776 (nnheader-translate-file-chars file))))))
2777 (gnus-make-directory (file-name-directory result))
2778 (set variable result)))
2780 (defun gnus-article-archive-name (group)
2781 "Return the first instance of an \"Archive-name\" in the current buffer."
2782 (let ((case-fold-search t))
2783 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
2784 (nnheader-concat gnus-article-save-directory
2785 (match-string 1)))))
2787 (defun gnus-article-nndoc-name (group)
2788 "If GROUP is an nndoc group, return the name of the parent group."
2789 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
2790 (gnus-group-get-parameter group 'save-article-group)))
2792 (defun gnus-summary-save-in-rmail (&optional filename)
2793 "Append this article to Rmail file.
2794 Optional argument FILENAME specifies file name.
2795 Directory to save to is default to `gnus-article-save-directory'."
2796 (setq filename (gnus-read-save-file-name
2797 "Save %s in rmail file:" filename
2798 gnus-rmail-save-name gnus-newsgroup-name
2799 gnus-current-headers 'gnus-newsgroup-last-rmail))
2800 (gnus-eval-in-buffer-window gnus-save-article-buffer
2804 (gnus-output-to-rmail filename))))
2807 (defun gnus-summary-save-in-mail (&optional filename)
2808 "Append this article to Unix mail file.
2809 Optional argument FILENAME specifies file name.
2810 Directory to save to is default to `gnus-article-save-directory'."
2811 (setq filename (gnus-read-save-file-name
2812 "Save %s in Unix mail file:" filename
2813 gnus-mail-save-name gnus-newsgroup-name
2814 gnus-current-headers 'gnus-newsgroup-last-mail))
2815 (gnus-eval-in-buffer-window gnus-save-article-buffer
2819 (if (and (file-readable-p filename)
2820 (mail-file-babyl-p filename))
2821 (rmail-output-to-rmail-file filename t)
2822 (gnus-output-to-mail filename)))))
2825 (defun gnus-summary-save-in-file (&optional filename overwrite)
2826 "Append this article to file.
2827 Optional argument FILENAME specifies file name.
2828 Directory to save to is default to `gnus-article-save-directory'."
2829 (setq filename (gnus-read-save-file-name
2830 "Save %s in file:" filename
2831 gnus-file-save-name gnus-newsgroup-name
2832 gnus-current-headers 'gnus-newsgroup-last-file))
2833 (gnus-eval-in-buffer-window gnus-save-article-buffer
2837 (when (and overwrite
2838 (file-exists-p filename))
2839 (delete-file filename))
2840 (gnus-output-to-file filename))))
2843 (defun gnus-summary-write-to-file (&optional filename)
2844 "Write this article to a file, overwriting it if the file exists.
2845 Optional argument FILENAME specifies file name.
2846 The directory to save in defaults to `gnus-article-save-directory'."
2847 (gnus-summary-save-in-file nil t))
2849 (defun gnus-summary-save-body-in-file (&optional filename)
2850 "Append this article body to a file.
2851 Optional argument FILENAME specifies file name.
2852 The directory to save in defaults to `gnus-article-save-directory'."
2853 (setq filename (gnus-read-save-file-name
2854 "Save %s body in file:" filename
2855 gnus-file-save-name gnus-newsgroup-name
2856 gnus-current-headers 'gnus-newsgroup-last-file))
2857 (gnus-eval-in-buffer-window gnus-save-article-buffer
2861 (when (article-goto-body)
2862 (narrow-to-region (point) (point-max)))
2863 (gnus-output-to-file filename))))
2866 (defun gnus-summary-save-in-pipe (&optional command)
2867 "Pipe this article to subprocess."
2869 (cond ((and (eq command 'default)
2870 gnus-last-shell-command)
2871 gnus-last-shell-command)
2876 "Shell command on %s: "
2877 (if (and gnus-number-of-articles-to-be-saved
2878 (> gnus-number-of-articles-to-be-saved 1))
2879 (format "these %d articles"
2880 gnus-number-of-articles-to-be-saved)
2882 gnus-last-shell-command))))
2883 (when (string-equal command "")
2884 (if gnus-last-shell-command
2885 (setq command gnus-last-shell-command)
2886 (error "A command is required")))
2887 (gnus-eval-in-buffer-window gnus-article-buffer
2890 (shell-command-on-region (point-min) (point-max) command nil)))
2891 (setq gnus-last-shell-command command))
2893 (defun gnus-summary-pipe-to-muttprint (&optional command)
2894 "Pipe this article to muttprint."
2895 (setq command (read-string
2896 "Print using command: " gnus-summary-muttprint-program
2897 nil gnus-summary-muttprint-program))
2898 (gnus-summary-save-in-pipe command))
2900 ;;; Article file names when saving.
2902 (defun gnus-capitalize-newsgroup (newsgroup)
2903 "Capitalize NEWSGROUP name."
2904 (when (not (zerop (length newsgroup)))
2905 (concat (char-to-string (upcase (aref newsgroup 0)))
2906 (substring newsgroup 1))))
2908 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
2909 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2910 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
2911 Otherwise, it is like ~/News/news/group/num."
2914 (concat (if (gnus-use-long-file-name 'not-save)
2915 (gnus-capitalize-newsgroup newsgroup)
2916 (gnus-newsgroup-directory-form newsgroup))
2917 "/" (int-to-string (mail-header-number headers)))
2918 gnus-article-save-directory)))
2920 (string-equal (file-name-directory default)
2921 (file-name-directory last-file))
2922 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2924 (or last-file default))))
2926 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
2927 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2928 If variable `gnus-use-long-file-name' is non-nil, it is
2929 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
2932 (concat (if (gnus-use-long-file-name 'not-save)
2934 (gnus-newsgroup-directory-form newsgroup))
2935 "/" (int-to-string (mail-header-number headers)))
2936 gnus-article-save-directory)))
2938 (string-equal (file-name-directory default)
2939 (file-name-directory last-file))
2940 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2942 (or last-file default))))
2944 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
2945 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2946 If variable `gnus-use-long-file-name' is non-nil, it is
2947 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
2950 (if (gnus-use-long-file-name 'not-save)
2953 (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup))
2955 gnus-article-save-directory)))
2957 (defun gnus-sender-save-name (newsgroup headers &optional last-file)
2958 "Generate file name from sender."
2959 (let ((from (mail-header-from headers)))
2961 (if (and from (string-match "\\([^ <]+\\)@" from))
2962 (match-string 1 from)
2964 gnus-article-save-directory)))
2966 (defun article-verify-x-pgp-sig ()
2969 (if (gnus-buffer-live-p gnus-original-article-buffer)
2970 (let ((sig (with-current-buffer gnus-original-article-buffer
2971 (gnus-fetch-field "X-PGP-Sig")))
2975 (mml2015-clear-verify-function))
2977 (insert-buffer gnus-original-article-buffer)
2978 (setq items (split-string sig))
2979 (message-narrow-to-head)
2980 (let ((inhibit-point-motion-hooks t)
2981 (case-fold-search t))
2982 ;; Don't verify multiple headers.
2983 (setq headers (mapconcat (lambda (header)
2985 (mail-fetch-field header) "\n"))
2986 (split-string (nth 1 items) ",") "")))
2987 (delete-region (point-min) (point-max))
2988 (insert "-----BEGIN PGP SIGNED MESSAGE-----\n\n")
2989 (insert "X-Signed-Headers: " (nth 1 items) "\n")
2994 (if (looking-at "^-")
2997 (insert "\n-----BEGIN PGP SIGNATURE-----\n")
2998 (insert "Version: " (car items) "\n\n")
2999 (insert (mapconcat 'identity (cddr items) "\n"))
3000 (insert "\n-----END PGP SIGNATURE-----\n")
3001 (let ((mm-security-handle (list (format "multipart/signed"))))
3002 (mml2015-clean-buffer)
3003 (let ((coding-system-for-write (or gnus-newsgroup-charset
3005 (funcall (mml2015-clear-verify-function)))
3007 (or (mm-handle-multipart-ctl-parameter
3008 mm-security-handle 'gnus-details)
3009 (mm-handle-multipart-ctl-parameter
3010 mm-security-handle 'gnus-info)))))
3012 (let (buffer-read-only bface eface)
3014 (message-narrow-to-head)
3015 (goto-char (point-max))
3017 (setq bface (get-text-property (gnus-point-at-bol) 'face)
3018 eface (get-text-property (1- (gnus-point-at-eol)) 'face))
3019 (message-remove-header "X-Gnus-PGP-Verify")
3020 (if (re-search-forward "^X-PGP-Sig:" nil t)
3022 (goto-char (point-max)))
3023 (narrow-to-region (point) (point))
3024 (insert "X-Gnus-PGP-Verify: " info "\n")
3025 (goto-char (point-min))
3028 (if (not (looking-at "^[ \t]"))
3032 (goto-char (point-min))
3033 (when (looking-at "\\([^:]+\\): *")
3034 (put-text-property (match-beginning 1) (1+ (match-end 1))
3036 (put-text-property (match-end 0) (point-max)
3037 'face eface)))))))))
3039 (defun article-verify-cancel-lock ()
3040 "Verify Cancel-Lock header."
3042 (if (gnus-buffer-live-p gnus-original-article-buffer)
3043 (canlock-verify gnus-original-article-buffer)))
3050 (setq afunc (car func)
3053 gfunc (intern (format "gnus-%s" func))))
3056 `(lambda (&optional interactive &rest args)
3057 ,(documentation afunc t)
3058 (interactive (list t))
3060 (set-buffer gnus-article-buffer)
3062 (call-interactively ',afunc)
3063 (apply ',afunc args))))))))
3064 '(article-hide-headers
3065 article-verify-x-pgp-sig
3066 article-verify-cancel-lock
3067 article-hide-boring-headers
3068 article-treat-overstrike
3069 article-fill-long-lines
3070 article-capitalize-sentences
3072 article-remove-leading-whitespace
3073 article-display-x-face
3074 article-de-quoted-unreadable
3075 article-de-base64-unreadable
3078 article-hide-list-identifiers
3080 article-strip-banner
3083 article-hide-signature
3084 article-strip-headers-in-body
3085 article-remove-trailing-blank-lines
3086 article-strip-leading-blank-lines
3087 article-strip-multiple-blank-lines
3088 article-strip-leading-space
3089 article-strip-trailing-space
3090 article-strip-blank-lines
3091 article-strip-all-blank-lines
3092 article-replace-with-quoted-text
3094 article-date-english
3095 article-date-iso8601
3096 article-date-original
3098 article-decode-mime-words
3099 article-decode-charset
3100 article-decode-encoded-words
3104 article-treat-dumbquotes
3105 article-normalize-headers
3106 (article-show-all . gnus-article-show-all-headers))))
3109 ;;; Gnus article mode
3112 (put 'gnus-article-mode 'mode-class 'special)
3114 (set-keymap-parent gnus-article-mode-map widget-keymap)
3116 (gnus-define-keys gnus-article-mode-map
3117 " " gnus-article-goto-next-page
3118 "\177" gnus-article-goto-prev-page
3119 [delete] gnus-article-goto-prev-page
3120 [backspace] gnus-article-goto-prev-page
3121 "\C-c^" gnus-article-refer-article
3122 "h" gnus-article-show-summary
3123 "s" gnus-article-show-summary
3124 "\C-c\C-m" gnus-article-mail
3125 "?" gnus-article-describe-briefly
3126 "e" gnus-summary-edit-article
3127 "<" beginning-of-buffer
3129 "\C-c\C-i" gnus-info-find-node
3131 "\C-hk" gnus-article-describe-key
3132 "\C-hc" gnus-article-describe-key-briefly
3134 "\C-d" gnus-article-read-summary-keys
3135 "\M-*" gnus-article-read-summary-keys
3136 "\M-#" gnus-article-read-summary-keys
3137 "\M-^" gnus-article-read-summary-keys
3138 "\M-g" gnus-article-read-summary-keys)
3140 (substitute-key-definition
3141 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
3143 (defun gnus-article-make-menu-bar ()
3144 (unless (boundp 'gnus-article-commands-menu)
3145 (gnus-summary-make-menu-bar))
3146 (gnus-turn-off-edit-menu 'article)
3147 (unless (boundp 'gnus-article-article-menu)
3149 gnus-article-article-menu gnus-article-mode-map ""
3151 ["Scroll forwards" gnus-article-goto-next-page t]
3152 ["Scroll backwards" gnus-article-goto-prev-page t]
3153 ["Show summary" gnus-article-show-summary t]
3154 ["Fetch Message-ID at point" gnus-article-refer-article t]
3155 ["Mail to address at point" gnus-article-mail t]
3156 ["Send a bug report" gnus-bug t]))
3159 gnus-article-treatment-menu gnus-article-mode-map ""
3160 ;; Fixme: this should use :active (and maybe :visible).
3162 ["Hide headers" gnus-article-hide-headers t]
3163 ["Hide signature" gnus-article-hide-signature t]
3164 ["Hide citation" gnus-article-hide-citation t]
3165 ["Treat overstrike" gnus-article-treat-overstrike t]
3166 ["Remove carriage return" gnus-article-remove-cr t]
3167 ["Remove leading whitespace" gnus-article-remove-leading-whitespace t]
3168 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]
3169 ["Remove base64" gnus-article-de-base64-unreadable t]
3170 ["Treat html" gnus-article-wash-html t]
3171 ["Decode HZ" gnus-article-decode-HZ t]))
3173 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
3175 ;; Note "Post" menu is defined in gnus-sum.el for consistency
3177 (gnus-run-hooks 'gnus-article-menu-hook)))
3179 ;; Fixme: do something for the Emacs tool bar in Article mode a la
3182 (defun gnus-article-mode ()
3183 "Major mode for displaying an article.
3185 All normal editing commands are switched off.
3187 The following commands are available in addition to all summary mode
3189 \\<gnus-article-mode-map>
3190 \\[gnus-article-next-page]\t Scroll the article one page forwards
3191 \\[gnus-article-prev-page]\t Scroll the article one page backwards
3192 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
3193 \\[gnus-article-show-summary]\t Display the summary buffer
3194 \\[gnus-article-mail]\t Send a reply to the address near point
3195 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
3196 \\[gnus-info-find-node]\t Go to the Gnus info node"
3198 (gnus-simplify-mode-line)
3199 (setq mode-name "Article")
3200 (setq major-mode 'gnus-article-mode)
3201 (make-local-variable 'minor-mode-alist)
3202 (use-local-map gnus-article-mode-map)
3203 (when (gnus-visual-p 'article-menu 'menu)
3204 (gnus-article-make-menu-bar))
3205 (gnus-update-format-specifications nil 'article-mode)
3206 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
3207 (make-local-variable 'gnus-page-broken)
3208 (make-local-variable 'gnus-button-marker-list)
3209 (make-local-variable 'gnus-article-current-summary)
3210 (make-local-variable 'gnus-article-mime-handles)
3211 (make-local-variable 'gnus-article-decoded-p)
3212 (make-local-variable 'gnus-article-mime-handle-alist)
3213 (make-local-variable 'gnus-article-wash-types)
3214 (make-local-variable 'gnus-article-charset)
3215 (make-local-variable 'gnus-article-ignored-charsets)
3216 (gnus-set-default-directory)
3217 (buffer-disable-undo)
3218 (setq buffer-read-only t)
3219 (set-syntax-table gnus-article-mode-syntax-table)
3220 (mm-enable-multibyte)
3221 (gnus-run-hooks 'gnus-article-mode-hook))
3223 (defun gnus-article-setup-buffer ()
3224 "Initialize the article buffer."
3225 (let* ((name (if gnus-single-article-buffer "*Article*"
3226 (concat "*Article " gnus-newsgroup-name "*")))
3228 (progn (string-match "\\*Article" name)
3229 (concat " *Original Article"
3230 (substring name (match-end 0))))))
3231 (setq gnus-article-buffer name)
3232 (setq gnus-original-article-buffer original)
3233 (setq gnus-article-mime-handle-alist nil)
3234 ;; This might be a variable local to the summary buffer.
3235 (unless gnus-single-article-buffer
3237 (set-buffer gnus-summary-buffer)
3238 (setq gnus-article-buffer name)
3239 (setq gnus-original-article-buffer original)
3240 (gnus-set-global-variables)))
3241 (gnus-article-setup-highlight-words)
3242 ;; Init original article buffer.
3244 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
3245 (mm-enable-multibyte)
3246 (setq major-mode 'gnus-original-article-mode)
3247 (make-local-variable 'gnus-original-article))
3248 (if (get-buffer name)
3251 (when gnus-article-mime-handles
3252 (mm-destroy-parts gnus-article-mime-handles)
3253 (setq gnus-article-mime-handles nil))
3254 ;; Set it to nil in article-buffer!
3255 (setq gnus-article-mime-handle-alist nil)
3256 (buffer-disable-undo)
3257 (setq buffer-read-only t)
3258 (unless (eq major-mode 'gnus-article-mode)
3259 (gnus-article-mode))
3262 (set-buffer (gnus-get-buffer-create name))
3264 (make-local-variable 'gnus-summary-buffer)
3265 (gnus-summary-set-local-parameters gnus-newsgroup-name)
3266 (current-buffer)))))
3268 ;; Set article window start at LINE, where LINE is the number of lines
3269 ;; from the head of the article.
3270 (defun gnus-article-set-window-start (&optional line)
3272 (gnus-get-buffer-window gnus-article-buffer t)
3274 (set-buffer gnus-article-buffer)
3275 (goto-char (point-min))
3278 (gnus-message 6 "Moved to bookmark")
3279 (search-forward "\n\n" nil t)
3283 (defun gnus-article-prepare (article &optional all-headers header)
3284 "Prepare ARTICLE in article mode buffer.
3285 ARTICLE should either be an article number or a Message-ID.
3286 If ARTICLE is an id, HEADER should be the article headers.
3287 If ALL-HEADERS is non-nil, no headers are hidden."
3289 ;; Make sure we start in a summary buffer.
3290 (unless (eq major-mode 'gnus-summary-mode)
3291 (set-buffer gnus-summary-buffer))
3292 (setq gnus-summary-buffer (current-buffer))
3293 (let* ((gnus-article (if header (mail-header-number header) article))
3294 (summary-buffer (current-buffer))
3295 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
3296 (group gnus-newsgroup-name)
3299 (gnus-article-setup-buffer)
3300 (set-buffer gnus-article-buffer)
3301 ;; Deactivate active regions.
3302 (when (and (boundp 'transient-mark-mode)
3303 transient-mark-mode)
3304 (setq mark-active nil))
3305 (if (not (setq result (let ((buffer-read-only nil))
3306 (gnus-request-article-this-buffer
3308 ;; There is no such article.
3310 (when (and (numberp article)
3311 (not (memq article gnus-newsgroup-sparse)))
3312 (setq gnus-article-current
3313 (cons gnus-newsgroup-name article))
3314 (set-buffer gnus-summary-buffer)
3315 (setq gnus-current-article article)
3316 (if (eq (gnus-article-mark article) gnus-undownloaded-mark)
3318 (gnus-summary-set-agent-mark article)
3319 (message "Message marked for downloading"))
3320 (gnus-summary-mark-article article gnus-canceled-mark)
3321 (unless (memq article gnus-newsgroup-sparse)
3322 (gnus-error 1 "No such article (may have expired or been canceled)")))))
3323 (if (or (eq result 'pseudo)
3324 (eq result 'nneething))
3327 (set-buffer summary-buffer)
3328 (push article gnus-newsgroup-history)
3329 (setq gnus-last-article gnus-current-article
3330 gnus-current-article 0
3331 gnus-current-headers nil
3332 gnus-article-current nil)
3333 (if (eq result 'nneething)
3334 (gnus-configure-windows 'summary)
3335 (gnus-configure-windows 'article))
3336 (gnus-set-global-variables))
3337 (let ((gnus-article-mime-handle-alist-1
3338 gnus-article-mime-handle-alist))
3339 (gnus-set-mode-line 'article)))
3340 ;; The result from the `request' was an actual article -
3341 ;; or at least some text that is now displayed in the
3343 (when (and (numberp article)
3344 (not (eq article gnus-current-article)))
3345 ;; Seems like a new article has been selected.
3346 ;; `gnus-current-article' must be an article number.
3348 (set-buffer summary-buffer)
3349 (push article gnus-newsgroup-history)
3350 (setq gnus-last-article gnus-current-article
3351 gnus-current-article article
3352 gnus-current-headers
3353 (gnus-summary-article-header gnus-current-article)
3354 gnus-article-current
3355 (cons gnus-newsgroup-name gnus-current-article))
3356 (unless (vectorp gnus-current-headers)
3357 (setq gnus-current-headers nil))
3358 (gnus-summary-goto-subject gnus-current-article)
3359 (when (gnus-summary-show-thread)
3360 ;; If the summary buffer really was folded, the
3361 ;; previous goto may not actually have gone to
3362 ;; the right article, but the thread root instead.
3364 (gnus-summary-goto-subject gnus-current-article))
3365 (gnus-run-hooks 'gnus-mark-article-hook)
3366 (gnus-set-mode-line 'summary)
3367 (when (gnus-visual-p 'article-highlight 'highlight)
3368 (gnus-run-hooks 'gnus-visual-mark-article-hook))
3369 ;; Set the global newsgroup variables here.
3370 (gnus-set-global-variables)
3371 (setq gnus-have-all-headers
3372 (or all-headers gnus-show-all-headers))))
3374 (gnus-configure-windows 'article))
3375 (when (or (numberp article)
3377 (gnus-article-prepare-display)
3379 (goto-char (point-min))
3380 (setq gnus-page-broken
3381 (when gnus-break-pages
3382 (gnus-narrow-to-page)
3384 (let ((gnus-article-mime-handle-alist-1
3385 gnus-article-mime-handle-alist))
3386 (gnus-set-mode-line 'article))
3388 (set-window-point (get-buffer-window (current-buffer)) (point))
3389 (gnus-configure-windows 'article)
3393 (defun gnus-article-prepare-display ()
3394 "Make the current buffer look like a nice article."
3395 ;; Hooks for getting information from the article.
3396 ;; This hook must be called before being narrowed.
3397 (let ((gnus-article-buffer (current-buffer))
3399 (unless (eq major-mode 'gnus-article-mode)
3400 (gnus-article-mode))
3401 (setq buffer-read-only nil
3402 gnus-article-wash-types nil)
3403 (gnus-run-hooks 'gnus-tmp-internal-hook)
3404 (when gnus-display-mime-function
3405 (funcall gnus-display-mime-function))
3406 (gnus-run-hooks 'gnus-article-prepare-hook)))
3409 ;;; Gnus MIME viewing functions
3412 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
3413 "The following specs can be used:
3415 %T MIME type, along with additional info
3416 %n The `name' parameter
3417 %d The description, if any
3418 %l The length of the encoded part
3419 %p The part identifier number
3420 %e Dots if the part isn't displayed")
3422 (defvar gnus-mime-button-line-format-alist
3423 '((?t gnus-tmp-type ?s)
3424 (?T gnus-tmp-type-long ?s)
3425 (?n gnus-tmp-name ?s)
3426 (?d gnus-tmp-description ?s)
3428 (?l gnus-tmp-length ?d)
3429 (?e gnus-tmp-dots ?s)))
3431 (defvar gnus-mime-button-commands
3432 '((gnus-article-press-button "\r" "Toggle Display")
3433 (gnus-mime-view-part "v" "View Interactively...")
3434 (gnus-mime-view-part-as-type "t" "View As Type...")
3435 (gnus-mime-view-part-as-charset "C" "View As charset...")
3436 (gnus-mime-save-part "o" "Save...")
3437 (gnus-mime-save-part-and-strip "\C-o" "Save and Strip")
3438 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
3439 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
3440 (gnus-mime-internalize-part "E" "View Internally")
3441 (gnus-mime-externalize-part "e" "View Externally")
3442 (gnus-mime-print-part "p" "Print")
3443 (gnus-mime-pipe-part "|" "Pipe To Command...")
3444 (gnus-mime-action-on-part "." "Take action on the part")))
3446 (defun gnus-article-mime-part-status ()
3447 (if gnus-article-mime-handle-alist-1
3448 (if (eq 1 (length gnus-article-mime-handle-alist-1))
3450 (format " (%d parts)" (length gnus-article-mime-handle-alist-1)))
3453 (defvar gnus-mime-button-map
3454 (let ((map (make-sparse-keymap)))
3455 (unless (>= (string-to-number emacs-version) 21)
3456 ;; XEmacs doesn't care.
3457 (set-keymap-parent map gnus-article-mode-map))
3458 (define-key map gnus-mouse-2 'gnus-article-push-button)
3459 (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
3460 (dolist (c gnus-mime-button-commands)
3461 (define-key map (cadr c) (car c)))
3464 (defun gnus-mime-button-menu (event)
3465 "Construct a context-sensitive menu of MIME commands."
3467 (save-window-excursion
3468 (let ((pos (event-start event)))
3469 (select-window (posn-window pos))
3470 (goto-char (posn-point pos))
3471 (gnus-article-check-buffer)
3472 (let ((response (x-popup-menu
3474 ("" ,@(mapcar (lambda (c)
3475 (cons (caddr c) (car c)))
3476 gnus-mime-button-commands))))))
3478 (call-interactively response))))))
3480 (defun gnus-mime-view-all-parts (&optional handles)
3481 "View all the MIME parts."
3483 (save-current-buffer
3484 (set-buffer gnus-article-buffer)
3485 (let ((handles (or handles gnus-article-mime-handles))
3486 (mail-parse-charset gnus-newsgroup-charset)
3487 (mail-parse-ignored-charsets
3488 (with-current-buffer gnus-summary-buffer
3489 gnus-newsgroup-ignored-charsets)))
3491 (mm-remove-parts handles)
3492 (goto-char (point-min))
3493 (or (search-forward "\n\n") (goto-char (point-max)))
3494 (let (buffer-read-only)
3495 (delete-region (point) (point-max))
3496 (mm-display-parts handles))))))
3498 (defun gnus-mime-save-part-and-strip ()
3499 "Save the MIME part under point then replace it with an external body."
3501 (gnus-article-check-buffer)
3502 (let* ((data (get-text-property (point) 'gnus-data))
3504 (handles gnus-article-mime-handles))
3505 (if (mm-multiple-handles gnus-article-mime-handles)
3506 (error "This function is not implemented"))
3507 (setq file (and data (mm-save-part data)))
3509 (with-current-buffer (mm-handle-buffer data)
3511 (insert "Content-Type: " (mm-handle-media-type data))
3512 (mml-insert-parameter-string (cdr (mm-handle-type data))
3515 (insert "Content-ID: " (message-make-message-id) "\n")
3516 (insert "Content-Transfer-Encoding: binary\n")
3519 (cdr (mm-make-handle nil
3520 `("message/external-body"
3521 (access-type . "LOCAL-FILE")
3523 (set-buffer gnus-summary-buffer)
3524 (gnus-article-edit-article
3527 (let ((mail-parse-charset (or gnus-article-charset
3528 ',gnus-newsgroup-charset))
3529 (mail-parse-ignored-charsets
3530 (or gnus-article-ignored-charsets
3531 ',gnus-newsgroup-ignored-charsets))
3532 (mbl mml-buffer-list))
3533 (setq mml-buffer-list nil)
3534 (insert-buffer gnus-original-article-buffer)
3535 (mime-to-mml ',handles)
3536 (setq gnus-article-mime-handles nil)
3537 (let ((mbl1 mml-buffer-list))
3538 (setq mml-buffer-list mbl)
3539 (set (make-local-variable 'mml-buffer-list) mbl1))
3540 ;; LOCAL argument of add-hook differs between GNU Emacs
3541 ;; and XEmacs. make-local-hook makes sure they are local.
3542 (make-local-hook 'kill-buffer-hook)
3543 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
3544 `(lambda (no-highlight)
3545 (let ((mail-parse-charset (or gnus-article-charset
3546 ',gnus-newsgroup-charset))
3547 (message-options message-options)
3548 (message-options-set-recipient)
3549 (mail-parse-ignored-charsets
3550 (or gnus-article-ignored-charsets
3551 ',gnus-newsgroup-ignored-charsets)))
3553 (mml-destroy-buffers)
3554 (remove-hook 'kill-buffer-hook
3555 'mml-destroy-buffers t)
3556 (kill-local-variable 'mml-buffer-list))
3557 (gnus-summary-edit-article-done
3558 ,(or (mail-header-references gnus-current-headers) "")
3559 ,(gnus-group-read-only-p)
3560 ,gnus-summary-buffer no-highlight))))))
3562 (defun gnus-mime-save-part ()
3563 "Save the MIME part under point."
3565 (gnus-article-check-buffer)
3566 (let ((data (get-text-property (point) 'gnus-data)))
3568 (mm-save-part data))))
3570 (defun gnus-mime-pipe-part ()
3571 "Pipe the MIME part under point to a process."
3573 (gnus-article-check-buffer)
3574 (let ((data (get-text-property (point) 'gnus-data)))
3576 (mm-pipe-part data))))
3578 (defun gnus-mime-view-part ()
3579 "Interactively choose a viewing method for the MIME part under point."
3581 (gnus-article-check-buffer)
3582 (let ((data (get-text-property (point) 'gnus-data)))
3584 (setq gnus-article-mime-handles
3586 gnus-article-mime-handles (setq data (copy-sequence data))))
3587 (mm-interactively-view-part data))))
3589 (defun gnus-mime-view-part-as-type-internal ()
3590 (gnus-article-check-buffer)
3591 (let* ((name (mail-content-type-get
3592 (mm-handle-type (get-text-property (point) 'gnus-data))
3594 (def-type (and name (mm-default-file-encoding name))))
3595 (and def-type (cons def-type 0))))
3597 (defun gnus-mime-view-part-as-type (&optional mime-type)
3598 "Choose a MIME media type, and view the part as such."
3601 (setq mime-type (completing-read
3602 "View as MIME type: "
3603 (mapcar #'list (mailcap-mime-types))
3605 (gnus-mime-view-part-as-type-internal))))
3606 (gnus-article-check-buffer)
3607 (let ((handle (get-text-property (point) 'gnus-data)))
3610 (mm-make-handle (mm-handle-buffer handle)
3611 (cons mime-type (cdr (mm-handle-type handle)))
3612 (mm-handle-encoding handle)
3613 (mm-handle-undisplayer handle)
3614 (mm-handle-disposition handle)
3615 (mm-handle-description handle)
3617 (mm-handle-id handle)))
3618 (setq gnus-article-mime-handles
3619 (mm-merge-handles gnus-article-mime-handles handle))
3620 (gnus-mm-display-part handle))))
3622 (defun gnus-mime-copy-part (&optional handle)
3623 "Put the MIME part under point into a new buffer."
3625 (gnus-article-check-buffer)
3626 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3627 (contents (and handle (mm-get-part handle)))
3629 (file-name-nondirectory
3631 (mail-content-type-get (mm-handle-type handle) 'name)
3632 (mail-content-type-get (mm-handle-type handle)
3635 (buffer (and base (generate-new-buffer base))))
3637 (switch-to-buffer buffer)
3639 ;; We do it this way to make `normal-mode' set the appropriate mode.
3642 (setq buffer-file-name (expand-file-name base))
3644 (setq buffer-file-name nil))
3645 (goto-char (point-min)))))
3647 (defun gnus-mime-print-part (&optional handle)
3648 "Print the MIME part under point."
3650 (gnus-article-check-buffer)
3651 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3652 (contents (and handle (mm-get-part handle)))
3653 (file (make-temp-name (expand-file-name "mm." dir)))
3654 (printer (mailcap-mime-info (mm-handle-type handle) "print")))
3659 (with-temp-file file
3661 (call-process shell-file-name nil
3662 (generate-new-buffer " *mm*")
3664 shell-command-switch
3666 printer file (mm-handle-type handle))))
3670 (gnus-print-buffer))))))
3672 (defun gnus-mime-inline-part (&optional handle arg)
3673 "Insert the MIME part under point into the current buffer."
3674 (interactive (list nil current-prefix-arg))
3675 (gnus-article-check-buffer)
3676 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3681 (if (and (not arg) (mm-handle-undisplayer handle))
3682 (mm-remove-part handle)
3683 (setq contents (mm-get-part handle))
3686 (setq charset (or (mail-content-type-get
3687 (mm-handle-type handle) 'charset)
3688 gnus-newsgroup-charset)))
3690 (if (mm-handle-undisplayer handle)
3691 (mm-remove-part handle))
3694 gnus-summary-show-article-charset-alist))
3695 (mm-read-coding-system "Charset: ")))))
3697 (mm-insert-inline handle
3699 (setq charset (mm-charset-to-coding-system
3701 (not (eq charset 'ascii)))
3702 (mm-decode-coding-string contents charset)
3706 (defun gnus-mime-view-part-as-charset (&optional handle arg)
3707 "Insert the MIME part under point into the current buffer using the
3709 (interactive (list nil current-prefix-arg))
3710 (gnus-article-check-buffer)
3711 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3716 (if (mm-handle-undisplayer handle)
3717 (mm-remove-part handle))
3718 (let ((gnus-newsgroup-charset
3720 gnus-summary-show-article-charset-alist))
3721 (mm-read-coding-system "Charset: ")))
3722 (gnus-newsgroup-ignored-charsets 'gnus-all))
3723 (gnus-article-press-button)))))
3725 (defun gnus-mime-externalize-part (&optional handle)
3726 "View the MIME part under point with an external viewer."
3728 (gnus-article-check-buffer)
3729 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3730 (mm-user-display-methods nil)
3731 (mm-inlined-types nil)
3732 (mail-parse-charset gnus-newsgroup-charset)
3733 (mail-parse-ignored-charsets
3734 (save-excursion (set-buffer gnus-summary-buffer)
3735 gnus-newsgroup-ignored-charsets)))
3737 (if (mm-handle-undisplayer handle)
3738 (mm-remove-part handle)
3739 (mm-display-part handle)))))
3741 (defun gnus-mime-internalize-part (&optional handle)
3742 "View the MIME part under point with an internal viewer.
3743 If no internal viewer is available, use an external viewer."
3745 (gnus-article-check-buffer)
3746 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3747 (mm-inlined-types '(".*"))
3748 (mm-inline-large-images t)
3749 (mail-parse-charset gnus-newsgroup-charset)
3750 (mail-parse-ignored-charsets
3751 (save-excursion (set-buffer gnus-summary-buffer)
3752 gnus-newsgroup-ignored-charsets)))
3754 (if (mm-handle-undisplayer handle)
3755 (mm-remove-part handle)
3756 (mm-display-part handle)))))
3758 (defun gnus-mime-action-on-part (&optional action)
3759 "Do something with the MIME attachment at \(point\)."
3761 (list (completing-read "Action: " gnus-mime-action-alist)))
3762 (gnus-article-check-buffer)
3763 (let ((action-pair (assoc action gnus-mime-action-alist)))
3765 (funcall (cdr action-pair)))))
3767 (defun gnus-article-part-wrapper (n function)
3768 (save-current-buffer
3769 (set-buffer gnus-article-buffer)
3770 (when (> n (length gnus-article-mime-handle-alist))
3771 (error "No such part"))
3772 (gnus-article-goto-part n)
3773 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
3774 (funcall function handle))))
3776 (defun gnus-article-pipe-part (n)
3777 "Pipe MIME part N, which is the numerical prefix."
3779 (gnus-article-part-wrapper n 'mm-pipe-part))
3781 (defun gnus-article-save-part (n)
3782 "Save MIME part N, which is the numerical prefix."
3784 (gnus-article-part-wrapper n 'mm-save-part))
3786 (defun gnus-article-interactively-view-part (n)
3787 "View MIME part N interactively, which is the numerical prefix."
3789 (gnus-article-part-wrapper n 'mm-interactively-view-part))
3791 (defun gnus-article-copy-part (n)
3792 "Copy MIME part N, which is the numerical prefix."
3794 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
3796 (defun gnus-article-view-part-as-charset (n)
3797 "Copy MIME part N, which is the numerical prefix."
3799 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-charset))
3801 (defun gnus-article-externalize-part (n)
3802 "View MIME part N externally, which is the numerical prefix."
3804 (gnus-article-part-wrapper n 'gnus-mime-externalize-part))
3806 (defun gnus-article-inline-part (n)
3807 "Inline MIME part N, which is the numerical prefix."
3809 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
3811 (defun gnus-article-mime-match-handle-first (condition)
3813 (let ((alist gnus-article-mime-handle-alist) ihandle n)
3814 (while (setq ihandle (pop alist))
3816 ((functionp condition)
3817 (funcall condition (cdr ihandle)))
3818 ((eq condition 'undisplayed)
3819 (not (or (mm-handle-undisplayer (cdr ihandle))
3820 (equal (mm-handle-media-type (cdr ihandle))
3821 "multipart/alternative"))))
3822 ((eq condition 'undisplayed-alternative)
3823 (not (mm-handle-undisplayer (cdr ihandle))))
3825 (gnus-article-goto-part (car ihandle))
3826 (or (not n) (< (car ihandle) n)))
3827 (setq n (car ihandle))))
3831 (defun gnus-article-view-part (&optional n)
3832 "View MIME part N, which is the numerical prefix."
3834 (save-current-buffer
3835 (set-buffer gnus-article-buffer)
3836 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
3837 gnus-article-mime-match-handle-function)))
3838 (when (> n (length gnus-article-mime-handle-alist))
3839 (error "No such part"))
3840 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
3841 (when (gnus-article-goto-part n)
3842 (if (equal (car handle) "multipart/alternative")
3843 (gnus-article-press-button)
3844 (when (eq (gnus-mm-display-part handle) 'internal)
3845 (gnus-set-window-start)))))))
3847 (defsubst gnus-article-mime-total-parts ()
3848 (if (bufferp (car gnus-article-mime-handles))
3850 (1- (length gnus-article-mime-handles))))
3852 (defun gnus-mm-display-part (handle)
3853 "Display HANDLE and fix MIME button."
3854 (let ((id (get-text-property (point) 'gnus-part))
3859 (let ((window (selected-window))
3860 (mail-parse-charset gnus-newsgroup-charset)
3861 (mail-parse-ignored-charsets
3862 (save-excursion (set-buffer gnus-summary-buffer)
3863 gnus-newsgroup-ignored-charsets)))
3866 (let ((win (gnus-get-buffer-window (current-buffer) t))
3869 (select-window win))
3872 (if (mm-handle-displayed-p handle)
3873 ;; This will remove the part.
3874 (mm-display-part handle)
3876 (narrow-to-region (point)
3877 (if (eobp) (point) (1+ (point))))
3878 (mm-display-part handle)
3879 ;; We narrow to the part itself and
3880 ;; then call the treatment functions.
3881 (goto-char (point-min))
3883 (narrow-to-region (point) (point-max))
3886 (gnus-article-mime-total-parts)
3887 (mm-handle-media-type handle)))))
3888 (if (window-live-p window)
3889 (select-window window)))))
3891 (delete-region (gnus-point-at-bol) (progn (forward-line 1) (point)))
3892 (gnus-insert-mime-button
3893 handle id (list (mm-handle-displayed-p handle)))
3894 (goto-char point))))
3896 (defun gnus-article-goto-part (n)
3897 "Go to MIME part N."
3898 (let ((point (text-property-any (point-min) (point-max) 'gnus-part n)))
3900 (goto-char point))))
3902 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
3903 (let ((gnus-tmp-name
3904 (or (mail-content-type-get (mm-handle-type handle) 'name)
3905 (mail-content-type-get (mm-handle-disposition handle) 'filename)
3906 (mail-content-type-get (mm-handle-type handle) 'url)
3908 (gnus-tmp-type (mm-handle-media-type handle))
3909 (gnus-tmp-description
3910 (mail-decode-encoded-word-string (or (mm-handle-description handle)
3913 (if (if displayed (car displayed)
3914 (mm-handle-displayed-p handle))
3916 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
3918 gnus-tmp-type-long b e)
3919 (when (string-match ".*/" gnus-tmp-name)
3920 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
3921 (setq gnus-tmp-type-long (concat gnus-tmp-type
3922 (and (not (equal gnus-tmp-name ""))
3923 (concat "; " gnus-tmp-name))))
3924 (unless (equal gnus-tmp-description "")
3925 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
3930 gnus-mime-button-line-format gnus-mime-button-line-format-alist
3931 `(keymap ,gnus-mime-button-map
3932 ,@(if (>= (string-to-number emacs-version) 21)
3934 (list 'local-map gnus-mime-button-map))
3935 gnus-callback gnus-mm-display-part
3936 gnus-part ,gnus-tmp-id
3937 article-type annotation
3940 (widget-convert-button
3943 :action 'gnus-widget-press-button
3944 :button-keymap gnus-mime-button-map
3946 (lambda (widget/window &optional overlay pos)
3947 ;; Needed to properly clear the message due to a bug in
3948 ;; wid-edit (XEmacs only).
3949 (if (boundp 'help-echo-owns-message)
3950 (setq help-echo-owns-message t))
3952 "%S: %s the MIME part; %S: more options"
3953 (aref gnus-mouse-2 0)
3954 ;; XEmacs will get a single widget arg; Emacs 21 will get
3955 ;; window, overlay, position.
3956 (if (mm-handle-displayed-p
3958 (with-current-buffer (gnus-overlay-buffer overlay)
3959 (widget-get (widget-at (gnus-overlay-start overlay))
3961 (widget-get widget/window :mime-handle)))
3963 (aref gnus-down-mouse-3 0))))))
3965 (defun gnus-widget-press-button (elems el)
3966 (goto-char (widget-get elems :from))
3967 (gnus-article-press-button))
3969 (defvar gnus-displaying-mime nil)
3971 (defun gnus-display-mime (&optional ihandles)
3972 "Display the MIME parts."
3974 (save-selected-window
3975 (let ((window (get-buffer-window gnus-article-buffer))
3978 (select-window window)
3979 ;; We have to do this since selecting the window
3980 ;; may change the point. So we set the window point.
3981 (set-window-point window point)))
3982 (let* ((handles (or ihandles (mm-dissect-buffer) (mm-uu-dissect)))
3983 buffer-read-only handle name type b e display)
3984 (when (and (not ihandles)
3985 (not gnus-displaying-mime))
3986 ;; Top-level call; we clean up.
3987 (when gnus-article-mime-handles
3988 (mm-destroy-parts gnus-article-mime-handles)
3989 (setq gnus-article-mime-handle-alist nil));; A trick.
3990 (setq gnus-article-mime-handles handles)
3991 ;; We allow users to glean info from the handles.
3992 (when gnus-article-mime-part-function
3993 (gnus-mime-part-function handles)))
3995 (or (not (stringp (car handles)))
3998 (when (and (not ihandles)
3999 (not gnus-displaying-mime))
4000 ;; Clean up for mime parts.
4002 (delete-region (point) (point-max)))
4003 (let ((gnus-displaying-mime t))
4004 (gnus-mime-display-part handles)))
4007 (narrow-to-region (point) (point-max))
4008 (gnus-treat-article nil 1 1)
4011 ;; Highlight the headers.
4015 (narrow-to-region (point-min) (point))
4016 (gnus-treat-article 'head))))))))
4018 (defvar gnus-mime-display-multipart-as-mixed nil)
4019 (defvar gnus-mime-display-multipart-alternative-as-mixed nil)
4020 (defvar gnus-mime-display-multipart-related-as-mixed nil)
4022 (defun gnus-mime-display-part (handle)
4025 ((not (stringp (car handle)))
4026 (gnus-mime-display-single handle))
4027 ;; User-defined multipart
4028 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
4029 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
4031 ;; multipart/alternative
4032 ((and (equal (car handle) "multipart/alternative")
4033 (not (or gnus-mime-display-multipart-as-mixed
4034 gnus-mime-display-multipart-alternative-as-mixed)))
4035 (let ((id (1+ (length gnus-article-mime-handle-alist))))
4036 (push (cons id handle) gnus-article-mime-handle-alist)
4037 (gnus-mime-display-alternative (cdr handle) nil nil id)))
4038 ;; multipart/related
4039 ((and (equal (car handle) "multipart/related")
4040 (not (or gnus-mime-display-multipart-as-mixed
4041 gnus-mime-display-multipart-related-as-mixed)))
4042 ;;;!!!We should find the start part, but we just default
4043 ;;;!!!to the first part.
4044 ;;(gnus-mime-display-part (cadr handle))
4045 ;;;!!! Most multipart/related is an HTML message plus images.
4046 ;;;!!! Unfortunately we are unable to let W3 display those
4047 ;;;!!! included images, so we just display it as a mixed multipart.
4048 ;;(gnus-mime-display-mixed (cdr handle))
4049 ;;;!!! No, w3 can display everything just fine.
4050 (gnus-mime-display-part (cadr handle)))
4051 ((equal (car handle) "multipart/signed")
4052 (or (memq 'signed gnus-article-wash-types)
4053 (push 'signed gnus-article-wash-types))
4054 (gnus-mime-display-security handle))
4055 ((equal (car handle) "multipart/encrypted")
4056 (or (memq 'encrypted gnus-article-wash-types)
4057 (push 'encrypted gnus-article-wash-types))
4058 (gnus-mime-display-security handle))
4059 ;; Other multiparts are handled like multipart/mixed.
4061 (gnus-mime-display-mixed (cdr handle)))))
4063 (defun gnus-mime-part-function (handles)
4064 (if (stringp (car handles))
4065 (mapcar 'gnus-mime-part-function (cdr handles))
4066 (funcall gnus-article-mime-part-function handles)))
4068 (defun gnus-mime-display-mixed (handles)
4069 (mapcar 'gnus-mime-display-part handles))
4071 (defun gnus-mime-display-single (handle)
4072 (let ((type (mm-handle-media-type handle))
4073 (ignored gnus-ignored-mime-types)
4080 (when (string-match (pop ignored) type)
4081 (throw 'ignored nil)))
4082 (if (and (setq not-attachment
4083 (and (not (mm-inline-override-p handle))
4084 (or (not (mm-handle-disposition handle))
4085 (equal (car (mm-handle-disposition handle))
4087 (mm-attachment-override-p handle))))
4088 (mm-automatic-display-p handle)
4090 (mm-inlinable-p handle)
4091 (mm-inlined-p handle))
4092 (mm-automatic-external-display-p type)))
4094 (when (equal (mm-handle-media-supertype handle) "text")
4096 (let ((id (1+ (length gnus-article-mime-handle-alist)))
4098 (push (cons id handle) gnus-article-mime-handle-alist)
4099 (when (or (not display)
4100 (not (gnus-unbuttonized-mime-type-p type)))
4101 ;(gnus-article-insert-newline)
4102 (gnus-insert-mime-button
4103 handle id (list (or display (and not-attachment text))))
4104 (gnus-article-insert-newline)
4105 ;(gnus-article-insert-newline)
4106 ;; Remember modify the number of forward lines.
4114 (let ((mail-parse-charset gnus-newsgroup-charset)
4115 (mail-parse-ignored-charsets
4116 (save-excursion (condition-case ()
4117 (set-buffer gnus-summary-buffer)
4119 gnus-newsgroup-ignored-charsets)))
4120 (mm-display-part handle t))
4121 (goto-char (point-max)))
4122 ((and text not-attachment)
4126 (gnus-article-insert-newline)
4127 (mm-insert-inline handle (mm-get-part handle))
4128 (goto-char (point-max))))
4132 (narrow-to-region beg (point))
4135 (gnus-article-mime-total-parts)
4136 (mm-handle-media-type handle)))))))))
4138 (defun gnus-unbuttonized-mime-type-p (type)
4139 "Say whether TYPE is to be unbuttonized."
4140 (unless gnus-inhibit-mime-unbuttonizing
4142 (let ((types gnus-unbuttonized-mime-types))
4144 (when (string-match (pop types) type)
4145 (throw 'found t)))))
4147 (let ((types gnus-buttonized-mime-types))
4149 (when (string-match (pop types) type)
4150 (throw 'found t)))))))))
4152 (defun gnus-article-insert-newline ()
4153 "Insert a newline, but mark it as undeletable."
4154 (gnus-put-text-property
4155 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
4157 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
4158 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
4161 handle buffer-read-only from props begend not-pref)
4162 (save-window-excursion
4165 (narrow-to-region (car ibegend)
4168 (goto-char (car ibegend))
4171 (delete-region (point-min) (point-max))
4172 (mm-remove-parts handles))
4173 (setq begend (list (point-marker)))
4175 (unless (setq not-pref (cadr (member preferred ihandles)))
4176 (setq not-pref (car ihandles)))
4179 (not (gnus-unbuttonized-mime-type-p
4180 "multipart/alternative")))
4181 (gnus-add-text-properties
4184 (insert (format "%d. " id))
4188 (unless ,(not ibegend)
4189 (setq gnus-article-mime-handle-alist
4190 ',gnus-article-mime-handle-alist))
4191 (gnus-mime-display-alternative
4192 ',ihandles ',not-pref ',begend ,id))
4193 ,@(if (>= (string-to-number emacs-version) 21)
4194 nil ;; XEmacs doesn't care
4195 (list 'local-map gnus-mime-button-map))
4196 ,gnus-mouse-face-prop ,gnus-article-mouse-face
4197 face ,gnus-article-button-face
4198 keymap ,gnus-mime-button-map
4201 (widget-convert-button 'link from (point)
4202 :action 'gnus-widget-press-button
4203 :button-keymap gnus-widget-button-keymap)
4205 (while (setq handle (pop handles))
4206 (gnus-add-text-properties
4209 (insert (format "(%c) %-18s"
4210 (if (equal handle preferred) ?* ? )
4211 (mm-handle-media-type handle)))
4215 (unless ,(not ibegend)
4216 (setq gnus-article-mime-handle-alist
4217 ',gnus-article-mime-handle-alist))
4218 (gnus-mime-display-alternative
4219 ',ihandles ',handle ',begend ,id))
4220 ,@(if (>= (string-to-number emacs-version) 21)
4221 nil ;; XEmacs doesn't care
4222 (list 'local-map gnus-mime-button-map))
4223 ,gnus-mouse-face-prop ,gnus-article-mouse-face
4224 face ,gnus-article-button-face
4225 keymap ,gnus-mime-button-map
4228 (widget-convert-button 'link from (point)
4229 :action 'gnus-widget-press-button
4230 :button-keymap gnus-widget-button-keymap)
4234 (if (stringp (car preferred))
4235 (gnus-display-mime preferred)
4236 (let ((mail-parse-charset gnus-newsgroup-charset)
4237 (mail-parse-ignored-charsets
4238 (save-excursion (set-buffer gnus-summary-buffer)
4239 gnus-newsgroup-ignored-charsets)))
4240 (mm-display-part preferred)
4244 (narrow-to-region (car begend) (point-max))
4246 nil (length gnus-article-mime-handle-alist)
4247 (gnus-article-mime-total-parts)
4248 (mm-handle-media-type handle))))))
4249 (goto-char (point-max))
4250 (setcdr begend (point-marker)))))
4252 (goto-char point))))
4254 (defconst gnus-article-wash-status-strings
4255 (let ((alist '((cite "c" "Possible hidden citation text"
4256 " " "All citation text visible")
4257 (headers "h" "Hidden headers"
4258 " " "All headers visible.")
4259 (pgp "p" "Encrypted or signed message status hidden"
4260 " " "No hidden encryption nor digital signature status")
4261 (signature "s" "Signature has been hidden"
4262 " " "Signature is visible")
4263 (overstrike "o" "Overstrike (^H) characters applied"
4264 " " "No overstrike characters applied")
4265 (emphasis "e" "/*_Emphasis_*/ characters applied"
4266 " " "No /*_emphasis_*/ characters applied")))
4268 (dolist (entry alist result)
4269 (let ((key (nth 0 entry))
4270 (on (copy-sequence (nth 1 entry)))
4271 (on-help (nth 2 entry))
4272 (off (copy-sequence (nth 3 entry)))
4273 (off-help (nth 4 entry)))
4274 (put-text-property 0 1 'help-echo on-help on)
4275 (put-text-property 0 1 'help-echo off-help off)
4276 (push (list key on off) result))))
4277 "Alist of strings describing wash status in the mode line.
4278 Each entry has the form (KEY ON OF), where the KEY is a symbol
4279 representing the particular washing function, ON is the string to use
4280 in the article mode line when the washing function is active, and OFF
4281 is the string to use when it is inactive.")
4283 (defun gnus-gnus-article-wash-status-entry (key value)
4284 (let ((entry (assoc key gnus-article-wash-status-strings)))
4285 (if value (nth 1 entry) (nth 2 entry))))
4287 (defun gnus-article-wash-status ()
4288 "Return a string which display status of article washing."
4290 (set-buffer gnus-article-buffer)
4291 (let ((cite (memq 'cite gnus-article-wash-types))
4292 (headers (memq 'headers gnus-article-wash-types))
4293 (boring (memq 'boring-headers gnus-article-wash-types))
4294 (pgp (memq 'pgp gnus-article-wash-types))
4295 (pem (memq 'pem gnus-article-wash-types))
4296 (signed (memq 'signed gnus-article-wash-types))
4297 (encrypted (memq 'encrypted gnus-article-wash-types))
4298 (signature (memq 'signature gnus-article-wash-types))
4299 (overstrike (memq 'overstrike gnus-article-wash-types))
4300 (emphasis (memq 'emphasis gnus-article-wash-types)))
4301 (concat (gnus-gnus-article-wash-status-entry 'cite cite)
4302 (gnus-gnus-article-wash-status-entry 'headers
4303 (or headers boring))
4304 (gnus-gnus-article-wash-status-entry
4305 'pgp (or pgp pem signed encrypted))
4306 (gnus-gnus-article-wash-status-entry 'signature signature)
4307 (gnus-gnus-article-wash-status-entry 'overstrike overstrike)
4308 (gnus-gnus-article-wash-status-entry 'emphasis emphasis)))))
4310 (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
4312 (defun gnus-article-maybe-hide-headers ()
4313 "Hide unwanted headers if `gnus-have-all-headers' is nil.
4314 Provided for backwards compatibility."
4315 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
4316 (not (save-excursion (set-buffer gnus-summary-buffer)
4317 gnus-have-all-headers)))
4318 (not gnus-inhibit-hiding))
4319 (gnus-article-hide-headers)))
4323 (defun gnus-output-to-file (file-name)
4324 "Append the current article to a file named FILE-NAME."
4325 (let ((artbuf (current-buffer)))
4327 (insert-buffer-substring artbuf)
4328 ;; Append newline at end of the buffer as separator, and then
4330 (goto-char (point-max))
4332 (let ((file-name-coding-system nnmail-pathname-coding-system))
4333 (mm-append-to-file (point-min) (point-max) file-name))
4336 (defun gnus-narrow-to-page (&optional arg)
4337 "Narrow the article buffer to a page.
4338 If given a numerical ARG, move forward ARG pages."
4340 (setq arg (if arg (prefix-numeric-value arg) 0))
4342 (set-buffer gnus-article-buffer)
4343 (goto-char (point-min))
4345 ;; Remove any old next/prev buttons.
4346 (when (gnus-visual-p 'page-marker)
4347 (let ((buffer-read-only nil))
4348 (gnus-remove-text-with-property 'gnus-prev)
4349 (gnus-remove-text-with-property 'gnus-next)))
4352 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
4354 (re-search-forward page-delimiter nil 'move arg)))
4355 (goto-char (match-end 0)))
4358 (if (re-search-forward page-delimiter nil 'move)
4361 (when (and (gnus-visual-p 'page-marker)
4362 (not (= (point-min) 1)))
4364 (goto-char (point-min))
4365 (gnus-insert-prev-page-button)))
4366 (when (and (gnus-visual-p 'page-marker)
4367 (< (+ (point-max) 2) (buffer-size)))
4369 (goto-char (point-max))
4370 (gnus-insert-next-page-button)))))
4372 ;; Article mode commands
4374 (defun gnus-article-goto-next-page ()
4375 "Show the next page of the article."
4377 (when (gnus-article-next-page)
4378 (goto-char (point-min))
4379 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
4381 (defun gnus-article-goto-prev-page ()
4382 "Show the next page of the article."
4384 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
4385 (gnus-article-prev-page nil)))
4387 (defun gnus-article-next-page (&optional lines)
4388 "Show the next page of the current article.
4389 If end of article, return non-nil. Otherwise return nil.
4390 Argument LINES specifies lines to be scrolled up."
4392 (move-to-window-line -1)
4395 (and (pos-visible-in-window-p) ;Not continuation line.
4397 ;; Nothing in this page.
4398 (if (or (not gnus-page-broken)
4401 (widen) (forward-line 1) (eobp)))) ;Real end-of-buffer?
4403 (gnus-narrow-to-page 1) ;Go to next page.
4405 ;; More in this page.
4406 (let ((scroll-in-place nil))
4410 ;; Long lines may cause an end-of-buffer error.
4411 (goto-char (point-max)))))
4412 (move-to-window-line 0)
4415 (defun gnus-article-prev-page (&optional lines)
4416 "Show previous page of current article.
4417 Argument LINES specifies lines to be scrolled down."
4419 (move-to-window-line 0)
4420 (if (and gnus-page-broken
4422 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
4424 (gnus-narrow-to-page -1) ;Go to previous page.
4425 (goto-char (point-max))
4427 (let ((scroll-in-place nil))
4431 (beginning-of-buffer
4432 (goto-char (point-min))))
4433 (move-to-window-line 0)))))
4435 (defun gnus-article-refer-article ()
4436 "Read article specified by message-id around point."
4438 (let ((point (point)))
4439 (search-forward ">" nil t) ;Move point to end of "<....>".
4440 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
4441 (let ((message-id (match-string 1)))
4443 (set-buffer gnus-summary-buffer)
4444 (gnus-summary-refer-article message-id))
4446 (error "No references around point"))))
4448 (defun gnus-article-show-summary ()
4449 "Reconfigure windows to show summary buffer."
4451 (if (not (gnus-buffer-live-p gnus-summary-buffer))
4452 (error "There is no summary buffer for this article buffer")
4453 (gnus-article-set-globals)
4454 (gnus-configure-windows 'article)
4455 (gnus-summary-goto-subject gnus-current-article)
4456 (gnus-summary-position-point)))
4458 (defun gnus-article-describe-briefly ()
4459 "Describe article mode commands briefly."
4461 (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")))
4463 (defun gnus-article-summary-command ()
4464 "Execute the last keystroke in the summary buffer."
4466 (let ((obuf (current-buffer))
4467 (owin (current-window-configuration))
4469 (switch-to-buffer gnus-article-current-summary 'norecord)
4470 (setq func (lookup-key (current-local-map) (this-command-keys)))
4471 (call-interactively func)
4473 (set-window-configuration owin)
4474 (set-window-point (get-buffer-window (current-buffer)) (point))))
4476 (defun gnus-article-summary-command-nosave ()
4477 "Execute the last keystroke in the summary buffer."
4480 (pop-to-buffer gnus-article-current-summary 'norecord)
4481 (setq func (lookup-key (current-local-map) (this-command-keys)))
4482 (call-interactively func)))
4484 (defun gnus-article-check-buffer ()
4485 "Beep if not in an article buffer."
4486 (unless (equal major-mode 'gnus-article-mode)
4487 (error "Command invoked outside of a Gnus article buffer")))
4489 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
4490 "Read a summary buffer key sequence and execute it from the article buffer."
4492 (gnus-article-check-buffer)
4494 '("q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F"
4495 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
4496 "=" "^" "\M-^" "|"))
4502 '("n" "Gn" "p" "Gp"))
4505 (set-buffer gnus-article-current-summary)
4506 (let (gnus-pick-mode)
4507 (push (or key last-command-event) unread-command-events)
4508 (setq keys (if (featurep 'xemacs)
4509 (events-to-keys (read-key-sequence nil))
4510 (read-key-sequence nil)))))
4514 (if (or (member keys nosaves)
4515 (member keys nosave-but-article)
4516 (member keys nosave-in-article))
4518 (save-window-excursion
4519 (pop-to-buffer gnus-article-current-summary 'norecord)
4520 ;; We disable the pick minor mode commands.
4521 (let (gnus-pick-mode)
4522 (setq func (lookup-key (current-local-map) keys))))
4526 (unless (member keys nosave-in-article)
4527 (set-buffer gnus-article-current-summary))
4528 (call-interactively func)
4529 (setq new-sum-point (point)))
4530 (when (member keys nosave-but-article)
4531 (pop-to-buffer gnus-article-buffer 'norecord)))
4532 ;; These commands should restore window configuration.
4533 (let ((obuf (current-buffer))
4534 (owin (current-window-configuration))
4536 (summary gnus-article-current-summary)
4537 func in-buffer selected)
4538 (if not-restore-window
4539 (pop-to-buffer summary 'norecord)
4540 (switch-to-buffer summary 'norecord))
4541 (setq in-buffer (current-buffer))
4542 ;; We disable the pick minor mode commands.
4543 (if (and (setq func (let (gnus-pick-mode)
4544 (lookup-key (current-local-map) keys)))
4547 (call-interactively func)
4548 (setq new-sum-point (point))
4549 (when (eq in-buffer (current-buffer))
4550 (setq selected (gnus-summary-select-article))
4552 (unless not-restore-window
4553 (set-window-configuration owin))
4554 (when (eq selected 'old)
4556 (set-window-start (get-buffer-window (current-buffer))
4558 (set-window-point (get-buffer-window (current-buffer))
4560 (let ((win (get-buffer-window gnus-article-current-summary)))
4562 (set-window-point win new-sum-point)))) )
4563 (switch-to-buffer gnus-article-buffer)
4566 (defun gnus-article-describe-key (key)
4567 "Display documentation of the function invoked by KEY. KEY is a string."
4568 (interactive "kDescribe key: ")
4569 (gnus-article-check-buffer)
4570 (if (eq (key-binding key) 'gnus-article-read-summary-keys)
4572 (set-buffer gnus-article-current-summary)
4573 (let (gnus-pick-mode)
4574 (if (featurep 'xemacs)
4576 (push (elt key 0) unread-command-events)
4577 (setq key (events-to-keys
4578 (read-key-sequence "Describe key: "))))
4579 (setq unread-command-events
4581 (lambda (x) (if (>= x 128) (list 'meta (- x 128)) x))
4582 (string-to-list key)))
4583 (setq key (read-key-sequence "Describe key: "))))
4585 (describe-key key)))
4587 (defun gnus-article-describe-key-briefly (key &optional insert)
4588 "Display documentation of the function invoked by KEY. KEY is a string."
4589 (interactive "kDescribe key: \nP")
4590 (gnus-article-check-buffer)
4591 (if (eq (key-binding key) 'gnus-article-read-summary-keys)
4593 (set-buffer gnus-article-current-summary)
4594 (let (gnus-pick-mode)
4595 (if (featurep 'xemacs)
4597 (push (elt key 0) unread-command-events)
4598 (setq key (events-to-keys
4599 (read-key-sequence "Describe key: "))))
4600 (setq unread-command-events
4602 (lambda (x) (if (>= x 128) (list 'meta (- x 128)) x))
4603 (string-to-list key)))
4604 (setq key (read-key-sequence "Describe key: "))))
4605 (describe-key-briefly key insert))
4606 (describe-key-briefly key insert)))
4608 (defun gnus-article-hide (&optional arg force)
4609 "Hide all the gruft in the current article.
4610 This means that PGP stuff, signatures, cited text and (some)
4611 headers will be hidden.
4612 If given a prefix, show the hidden text instead."
4613 (interactive (append (gnus-article-hidden-arg) (list 'force)))
4614 (gnus-article-hide-headers arg)
4615 (gnus-article-hide-list-identifiers arg)
4616 (gnus-article-hide-pgp arg)
4617 (gnus-article-hide-citation-maybe arg force)
4618 (gnus-article-hide-signature arg))
4620 (defun gnus-article-maybe-highlight ()
4621 "Do some article highlighting if article highlighting is requested."
4622 (when (gnus-visual-p 'article-highlight 'highlight)
4623 (gnus-article-highlight-some)))
4625 (defun gnus-check-group-server ()
4626 ;; Make sure the connection to the server is alive.
4627 (unless (gnus-server-opened
4628 (gnus-find-method-for-group gnus-newsgroup-name))
4629 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
4630 (gnus-request-group gnus-newsgroup-name t)))
4632 (defun gnus-request-article-this-buffer (article group)
4633 "Get an article and insert it into this buffer."
4634 (let (do-update-line sparse-header)
4638 (gnus-kill-all-overlays)
4639 (setq group (or group gnus-newsgroup-name))
4641 ;; Using `gnus-request-article' directly will insert the article into
4642 ;; `nntp-server-buffer' - so we'll save some time by not having to
4643 ;; copy it from the server buffer into the article buffer.
4645 ;; We only request an article by message-id when we do not have the
4646 ;; headers for it, so we'll have to get those.
4647 (when (stringp article)
4648 (gnus-read-header article))
4650 ;; If the article number is negative, that means that this article
4651 ;; doesn't belong in this newsgroup (possibly), so we find its
4652 ;; message-id and request it by id instead of number.
4653 (when (and (numberp article)
4655 (get-buffer gnus-summary-buffer)
4656 (gnus-buffer-exists-p gnus-summary-buffer))
4658 (set-buffer gnus-summary-buffer)
4659 (let ((header (gnus-summary-article-header article)))
4662 ((memq article gnus-newsgroup-sparse)
4663 ;; This is a sparse gap article.
4664 (setq do-update-line article)
4665 (setq article (mail-header-id header))
4666 (setq sparse-header (gnus-read-header article))
4667 (setq gnus-newsgroup-sparse
4668 (delq article gnus-newsgroup-sparse)))
4670 ;; It's a real article.
4671 (setq article (mail-header-id header)))
4673 ;; It is an extracted pseudo-article.
4674 (setq article 'pseudo)
4675 (gnus-request-pseudo-article header))))
4677 (let ((method (gnus-find-method-for-group
4678 gnus-newsgroup-name)))
4679 (when (and (eq (car method) 'nneething)
4681 (let ((dir (expand-file-name
4682 (mail-header-subject header)
4683 (file-name-as-directory
4684 (or (cadr (assq 'nneething-address method))
4686 (when (file-directory-p dir)
4687 (setq article 'nneething)
4688 (gnus-group-enter-directory dir))))))))
4691 ;; Refuse to select canceled articles.
4692 ((and (numberp article)
4694 (get-buffer gnus-summary-buffer)
4695 (gnus-buffer-exists-p gnus-summary-buffer)
4696 (eq (cdr (save-excursion
4697 (set-buffer gnus-summary-buffer)
4698 (assq article gnus-newsgroup-reads)))
4699 gnus-canceled-mark))
4701 ;; We first check `gnus-original-article-buffer'.
4702 ((and (get-buffer gnus-original-article-buffer)
4705 (set-buffer gnus-original-article-buffer)
4706 (and (equal (car gnus-original-article) group)
4707 (eq (cdr gnus-original-article) article))))
4708 (insert-buffer-substring gnus-original-article-buffer)
4710 ;; Check the backlog.
4711 ((and gnus-keep-backlog
4712 (gnus-backlog-request-article group article (current-buffer)))
4714 ;; Check asynchronous pre-fetch.
4715 ((gnus-async-request-fetched-article group article (current-buffer))
4716 (gnus-async-prefetch-next group article gnus-summary-buffer)
4717 (when (and (numberp article) gnus-keep-backlog)
4718 (gnus-backlog-enter-article group article (current-buffer)))
4721 ((and gnus-use-cache
4723 (gnus-cache-request-article article group))
4725 ;; Get the article and put into the article buffer.
4726 ((or (stringp article)
4728 (let ((gnus-override-method gnus-override-method)
4729 (methods (and (stringp article)
4730 gnus-refer-article-method))
4732 (buffer-read-only nil))
4733 (if (or (not (listp methods))
4734 (and (symbolp (car methods))
4735 (assq (car methods) nnoo-definition-alist)))
4736 (setq methods (list methods)))
4737 (when (and (null gnus-override-method)
4739 (setq gnus-override-method (pop methods)))
4741 (when (eq gnus-override-method 'current)
4742 (setq gnus-override-method
4743 (with-current-buffer gnus-summary-buffer
4744 gnus-current-select-method)))
4746 (gnus-kill-all-overlays)
4747 (let ((gnus-newsgroup-name group))
4748 (gnus-check-group-server))
4749 (when (gnus-request-article article group (current-buffer))
4750 (when (numberp article)
4751 (gnus-async-prefetch-next group article
4752 gnus-summary-buffer)
4753 (when gnus-keep-backlog
4754 (gnus-backlog-enter-article
4755 group article (current-buffer))))
4756 (setq result 'article))
4759 (setq gnus-override-method (pop methods))
4760 (setq result 'done))))
4761 (and (eq result 'article) 'article)))
4765 ;; Associate this article with the current summary buffer.
4766 (setq gnus-article-current-summary gnus-summary-buffer)
4768 ;; Take the article from the original article buffer
4769 ;; and place it in the buffer it's supposed to be in.
4770 (when (and (get-buffer gnus-article-buffer)
4771 (equal (buffer-name (current-buffer))
4772 (buffer-name (get-buffer gnus-article-buffer))))
4774 (if (get-buffer gnus-original-article-buffer)
4775 (set-buffer gnus-original-article-buffer)
4776 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
4777 (buffer-disable-undo)
4778 (setq major-mode 'gnus-original-article-mode)
4779 (setq buffer-read-only t))
4780 (let (buffer-read-only)
4782 (insert-buffer-substring gnus-article-buffer))
4783 (setq gnus-original-article (cons group article)))
4786 (run-hooks 'gnus-article-decode-hook)
4787 ;; Mark article as decoded or not.
4788 (setq gnus-article-decoded-p gnus-article-decode-hook))
4790 ;; Update sparse articles.
4791 (when (and do-update-line
4792 (or (numberp article)
4794 (let ((buf (current-buffer)))
4795 (set-buffer gnus-summary-buffer)
4796 (gnus-summary-update-article do-update-line sparse-header)
4797 (gnus-summary-goto-subject do-update-line nil t)
4798 (set-window-point (gnus-get-buffer-window (current-buffer) t)
4800 (set-buffer buf))))))
4806 (defcustom gnus-article-edit-mode-hook nil
4807 "Hook run in article edit mode buffers."
4808 :group 'gnus-article-various
4811 (defvar gnus-article-edit-done-function nil)
4813 (defvar gnus-article-edit-mode-map nil)
4815 ;; Should we be using derived.el for this?
4816 (unless gnus-article-edit-mode-map
4817 (setq gnus-article-edit-mode-map (make-sparse-keymap))
4818 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
4820 (gnus-define-keys gnus-article-edit-mode-map
4821 "\C-c\C-c" gnus-article-edit-done
4822 "\C-c\C-k" gnus-article-edit-exit)
4824 (gnus-define-keys (gnus-article-edit-wash-map
4825 "\C-c\C-w" gnus-article-edit-mode-map)
4826 "f" gnus-article-edit-full-stops))
4828 (define-derived-mode gnus-article-edit-mode text-mode "Article Edit"
4829 "Major mode for editing articles.
4830 This is an extended text-mode.
4832 \\{gnus-article-edit-mode-map}"
4833 (make-local-variable 'gnus-article-edit-done-function)
4834 (make-local-variable 'gnus-prev-winconf)
4835 (set (make-local-variable 'font-lock-defaults)
4836 '(message-font-lock-keywords t))
4837 (setq buffer-read-only nil)
4838 (buffer-enable-undo)
4841 (defun gnus-article-edit (&optional force)
4842 "Edit the current article.
4843 This will have permanent effect only in mail groups.
4844 If FORCE is non-nil, allow editing of articles even in read-only
4847 (when (and (not force)
4848 (gnus-group-read-only-p))
4849 (error "The current newsgroup does not support article editing"))
4850 (gnus-article-date-original)
4851 (gnus-article-edit-article
4853 `(lambda (no-highlight)
4855 (gnus-summary-edit-article-done
4856 ,(or (mail-header-references gnus-current-headers) "")
4857 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
4859 (defun gnus-article-edit-article (start-func exit-func)
4860 "Start editing the contents of the current article buffer."
4861 (let ((winconf (current-window-configuration)))
4862 (set-buffer gnus-article-buffer)
4863 (gnus-article-edit-mode)
4864 (funcall start-func)
4865 (set-buffer-modified-p nil)
4866 (gnus-configure-windows 'edit-article)
4867 (setq gnus-article-edit-done-function exit-func)
4868 (setq gnus-prev-winconf winconf)
4869 (gnus-message 6 "C-c C-c to end edits")))
4871 (defun gnus-article-edit-done (&optional arg)
4872 "Update the article edits and exit."
4874 (let ((func gnus-article-edit-done-function)
4875 (buf (current-buffer))
4876 (start (window-start)))
4877 ;; We remove all text props from the article buffer.
4879 (buffer-substring-no-properties (point-min) (point-max)))
4883 (let ((winconf gnus-prev-winconf))
4885 (set-window-configuration winconf)
4886 ;; Tippy-toe some to make sure that point remains where it was.
4887 (save-current-buffer
4889 (set-window-start (get-buffer-window (current-buffer)) start)
4893 (let ((buffer-read-only nil))
4895 ;; The cache and backlog have to be flushed somewhat.
4896 (when gnus-keep-backlog
4897 (gnus-backlog-remove-article
4898 (car gnus-article-current) (cdr gnus-article-current)))
4899 ;; Flush original article as well.
4901 (when (get-buffer gnus-original-article-buffer)
4902 (set-buffer gnus-original-article-buffer)
4903 (setq gnus-original-article nil)))
4904 (when gnus-use-cache
4905 (gnus-cache-update-article
4906 (car gnus-article-current) (cdr gnus-article-current))))
4908 (set-window-start (get-buffer-window buf) start)
4909 (set-window-point (get-buffer-window buf) (point))))
4911 (defun gnus-article-edit-exit ()
4912 "Exit the article editing without updating."
4914 (when (or (not (buffer-modified-p))
4915 (yes-or-no-p "Article modified; kill anyway? "))
4916 (let ((curbuf (current-buffer))
4918 (window-start (window-start)))
4920 (if (gnus-buffer-live-p gnus-original-article-buffer)
4921 (insert-buffer gnus-original-article-buffer))
4922 (let ((winconf gnus-prev-winconf))
4924 (set-window-configuration winconf)
4925 ;; Tippy-toe some to make sure that point remains where it was.
4926 (save-current-buffer
4928 (set-window-start (get-buffer-window (current-buffer)) window-start)
4931 (defun gnus-article-edit-full-stops ()
4932 "Interactively repair spacing at end of sentences."
4935 (goto-char (point-min))
4936 (search-forward-regexp "^$" nil t)
4937 (let ((case-fold-search nil))
4938 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
4941 ;;; Article highlights
4944 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
4946 ;;; Internal Variables:
4948 (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\\)\\)"
4949 "Regular expression that matches URLs."
4950 :group 'gnus-article-buttons
4953 (defcustom gnus-button-alist
4954 `(("<\\(url:[>\n\t ]*?\\)?\\(nntp\\|news\\):[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
4955 0 t gnus-button-handle-news 3)
4956 ("\\b\\(nntp\\|news\\):\\([^>\n\t ]*@[^>)!;:,\n\t ]*\\)" 0 t
4957 gnus-button-handle-news 2)
4958 ("\\(\\b<\\(url:[>\n\t ]*\\)?news:[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
4960 gnus-button-fetch-group 4)
4961 ("\\bnews:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
4962 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
4963 t gnus-button-message-id 3)
4964 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 2)
4965 ("mailto:\\([-a-zA-Z.@_+0-9%=?]+\\)" 0 t gnus-url-mailto 1)
4966 ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 1)
4968 ("\\binfo:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t
4969 gnus-button-handle-info 2)
4970 ;; This is how URLs _should_ be embedded in text...
4971 ("<URL: *\\([^<>]*\\)>" 0 t gnus-button-embedded-url 1)
4973 (,gnus-button-url-regexp 0 t browse-url 0))
4974 "*Alist of regexps matching buttons in article bodies.
4976 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
4977 REGEXP: is the string matching text around the button,
4978 BUTTON: is the number of the regexp grouping actually matching the button,
4979 FORM: is a lisp expression which must eval to true for the button to
4981 CALLBACK: is the function to call when the user push this button, and each
4982 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
4984 CALLBACK can also be a variable, in that case the value of that
4985 variable it the real callback function."
4986 :group 'gnus-article-buttons
4987 :type '(repeat (list regexp
4988 (integer :tag "Button")
4990 (function :tag "Callback")
4993 (integer :tag "Regexp group")))))
4995 (defcustom gnus-header-button-alist
4996 `(("^\\(References\\|Message-I[Dd]\\):" "<[^<>]+>"
4997 0 t gnus-button-message-id 0)
4998 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
4999 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
5000 0 t gnus-button-mailto 0)
5001 ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t browse-url 0)
5002 ("^Subject:" ,gnus-button-url-regexp 0 t browse-url 0)
5003 ("^[^:]+:" ,gnus-button-url-regexp 0 t browse-url 0)
5004 ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
5005 gnus-button-message-id 3))
5006 "*Alist of headers and regexps to match buttons in article heads.
5008 This alist is very similar to `gnus-button-alist', except that each
5009 alist has an additional HEADER element first in each entry:
5011 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
5013 HEADER is a regexp to match a header. For a fuller explanation, see
5014 `gnus-button-alist'."
5015 :group 'gnus-article-buttons
5016 :group 'gnus-article-headers
5017 :type '(repeat (list (regexp :tag "Header")
5019 (integer :tag "Button")
5021 (function :tag "Callback")
5024 (integer :tag "Regexp group")))))
5026 (defvar gnus-button-regexp nil)
5027 (defvar gnus-button-marker-list nil)
5028 ;; Regexp matching any of the regexps from `gnus-button-alist'.
5030 (defvar gnus-button-last nil)
5031 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
5035 (defun gnus-article-push-button (event)
5036 "Check text under the mouse pointer for a callback function.
5037 If the text under the mouse pointer has a `gnus-callback' property,
5038 call it with the value of the `gnus-data' text property."
5040 (set-buffer (window-buffer (posn-window (event-start event))))
5041 (let* ((pos (posn-point (event-start event)))
5042 (data (get-text-property pos 'gnus-data))
5043 (fun (get-text-property pos 'gnus-callback)))
5046 (funcall fun data))))
5048 (defun gnus-article-press-button ()
5049 "Check text at point for a callback function.
5050 If the text at point has a `gnus-callback' property,
5051 call it with the value of the `gnus-data' text property."
5053 (let* ((data (get-text-property (point) 'gnus-data))
5054 (fun (get-text-property (point) 'gnus-callback)))
5056 (funcall fun data))))
5058 (defun gnus-article-highlight (&optional force)
5059 "Highlight current article.
5060 This function calls `gnus-article-highlight-headers',
5061 `gnus-article-highlight-citation',
5062 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
5063 do the highlighting. See the documentation for those functions."
5064 (interactive (list 'force))
5065 (gnus-article-highlight-headers)
5066 (gnus-article-highlight-citation force)
5067 (gnus-article-highlight-signature)
5068 (gnus-article-add-buttons force)
5069 (gnus-article-add-buttons-to-head))
5071 (defun gnus-article-highlight-some (&optional force)
5072 "Highlight current article.
5073 This function calls `gnus-article-highlight-headers',
5074 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
5075 do the highlighting. See the documentation for those functions."
5076 (interactive (list 'force))
5077 (gnus-article-highlight-headers)
5078 (gnus-article-highlight-signature)
5079 (gnus-article-add-buttons))
5081 (defun gnus-article-highlight-headers ()
5082 "Highlight article headers as specified by `gnus-header-face-alist'."
5085 (set-buffer gnus-article-buffer)
5087 (let ((alist gnus-header-face-alist)
5088 (buffer-read-only nil)
5089 (case-fold-search t)
5090 (inhibit-point-motion-hooks t)
5091 entry regexp header-face field-face from hpoints fpoints)
5092 (article-narrow-to-head)
5093 (while (setq entry (pop alist))
5094 (goto-char (point-min))
5095 (setq regexp (concat "^\\("
5096 (if (string-equal "" (nth 0 entry))
5100 header-face (nth 1 entry)
5101 field-face (nth 2 entry))
5102 (while (and (re-search-forward regexp nil t)
5106 (unless (search-forward ":" nil t)
5108 (when (and header-face
5109 (not (memq (point) hpoints)))
5110 (push (point) hpoints)
5111 (gnus-put-text-property from (point) 'face header-face))
5112 (when (and field-face
5113 (not (memq (setq from (point)) fpoints)))
5115 (if (re-search-forward "^[^ \t]" nil t)
5117 (goto-char (point-max)))
5118 (gnus-put-text-property from (point) 'face field-face))))))))
5120 (defun gnus-article-highlight-signature ()
5121 "Highlight the signature in an article.
5122 It does this by highlighting everything after
5123 `gnus-signature-separator' using `gnus-signature-face'."
5126 (set-buffer gnus-article-buffer)
5127 (let ((buffer-read-only nil)
5128 (inhibit-point-motion-hooks t))
5130 (when (and gnus-signature-face
5131 (gnus-article-narrow-to-signature))
5132 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
5133 'face gnus-signature-face)
5135 (gnus-article-search-signature)
5136 (let ((start (match-beginning 0))
5137 (end (set-marker (make-marker) (1+ (match-end 0)))))
5138 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
5141 (defun gnus-button-in-region-p (b e prop)
5142 "Say whether PROP exists in the region."
5143 (text-property-not-all b e prop nil))
5145 (defun gnus-article-add-buttons (&optional force)
5146 "Find external references in the article and make buttons of them.
5147 \"External references\" are things like Message-IDs and URLs, as
5148 specified by `gnus-button-alist'."
5149 (interactive (list 'force))
5151 (set-buffer gnus-article-buffer)
5152 (let ((buffer-read-only nil)
5153 (inhibit-point-motion-hooks t)
5154 (case-fold-search t)
5155 (alist gnus-button-alist)
5157 ;; Remove all old markers.
5158 (let (marker entry new-list)
5159 (while (setq marker (pop gnus-button-marker-list))
5160 (if (or (< marker (point-min)) (>= marker (point-max)))
5161 (push marker new-list)
5163 (when (setq entry (gnus-button-entry))
5164 (put-text-property (match-beginning (nth 1 entry))
5165 (match-end (nth 1 entry))
5166 'gnus-callback nil))
5167 (set-marker marker nil)))
5168 (setq gnus-button-marker-list new-list))
5169 ;; We skip the headers.
5172 (while (setq entry (pop alist))
5173 (setq regexp (car entry))
5175 (while (re-search-forward regexp nil t)
5176 (let* ((start (and entry (match-beginning (nth 1 entry))))
5177 (end (and entry (match-end (nth 1 entry))))
5178 (from (match-beginning 0)))
5179 (when (and (or (eq t (nth 2 entry))
5180 (eval (nth 2 entry)))
5181 (not (gnus-button-in-region-p
5182 start end 'gnus-callback)))
5183 ;; That optional form returned non-nil, so we add the
5185 (gnus-article-add-button
5186 start end 'gnus-button-push
5187 (car (push (set-marker (make-marker) from)
5188 gnus-button-marker-list))))))))))
5190 ;; Add buttons to the head of an article.
5191 (defun gnus-article-add-buttons-to-head ()
5192 "Add buttons to the head of the article."
5195 (set-buffer gnus-article-buffer)
5197 (let ((buffer-read-only nil)
5198 (inhibit-point-motion-hooks t)
5199 (case-fold-search t)
5200 (alist gnus-header-button-alist)
5202 (article-narrow-to-head)
5204 ;; Each alist entry.
5205 (setq entry (car alist)
5207 (goto-char (point-min))
5208 (while (re-search-forward (car entry) nil t)
5209 ;; Each header matching the entry.
5210 (setq beg (match-beginning 0))
5211 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
5212 (match-beginning 0))
5215 (while (re-search-forward (nth 1 entry) end t)
5216 ;; Each match within a header.
5217 (let* ((entry (cdr entry))
5218 (start (match-beginning (nth 1 entry)))
5219 (end (match-end (nth 1 entry)))
5220 (form (nth 2 entry)))
5221 (goto-char (match-end 0))
5223 (gnus-article-add-button
5224 start end (nth 3 entry)
5225 (buffer-substring (match-beginning (nth 4 entry))
5226 (match-end (nth 4 entry)))))))
5227 (goto-char end)))))))
5229 ;;; External functions:
5231 (defun gnus-article-add-button (from to fun &optional data)
5232 "Create a button between FROM and TO with callback FUN and data DATA."
5233 (when gnus-article-button-face
5234 (gnus-overlay-put (gnus-make-overlay from to)
5235 'face gnus-article-button-face))
5236 (gnus-add-text-properties
5238 (nconc (and gnus-article-mouse-face
5239 (list gnus-mouse-face-prop gnus-article-mouse-face))
5240 (list 'gnus-callback fun)
5241 (and data (list 'gnus-data data))))
5242 (widget-convert-button 'link from to :action 'gnus-widget-press-button
5243 :button-keymap gnus-widget-button-keymap))
5245 ;;; Internal functions:
5247 (defun gnus-article-set-globals ()
5249 (set-buffer gnus-summary-buffer)
5250 (gnus-set-global-variables)))
5252 (defun gnus-signature-toggle (end)
5254 (set-buffer gnus-article-buffer)
5255 (let ((buffer-read-only nil)
5256 (inhibit-point-motion-hooks t))
5257 (if (text-property-any end (point-max) 'article-type 'signature)
5259 (setq gnus-article-wash-types
5260 (delq 'signature gnus-article-wash-types))
5261 (gnus-remove-text-properties-when
5262 'article-type 'signature end (point-max)
5263 (cons 'article-type (cons 'signature
5264 gnus-hidden-properties))))
5265 (or (memq 'signature gnus-article-wash-types)
5266 (push 'signature gnus-article-wash-types))
5267 (gnus-add-text-properties-when
5268 'article-type nil end (point-max)
5269 (cons 'article-type (cons 'signature
5270 gnus-hidden-properties)))))
5271 (let ((gnus-article-mime-handle-alist-1 gnus-article-mime-handle-alist))
5272 (gnus-set-mode-line 'article))))
5274 (defun gnus-button-entry ()
5275 ;; Return the first entry in `gnus-button-alist' matching this place.
5276 (let ((alist gnus-button-alist)
5279 (setq entry (pop alist))
5280 (if (looking-at (car entry))
5285 (defun gnus-button-push (marker)
5286 ;; Push button starting at MARKER.
5289 (let* ((entry (gnus-button-entry))
5290 (inhibit-point-motion-hooks t)
5292 (args (mapcar (lambda (group)
5293 (let ((string (match-string group)))
5294 (gnus-set-text-properties
5295 0 (length string) nil string)
5302 (fboundp (symbol-value fun)))
5303 (apply (symbol-value fun) args))
5305 (gnus-message 1 "You must define `%S' to use this button"
5306 (cons fun args)))))))
5308 (defun gnus-parse-news-url (url)
5309 (let (scheme server group message-id articles)
5312 (goto-char (point-min))
5313 (when (looking-at "\\([A-Za-z]+\\):")
5314 (setq scheme (match-string 1))
5315 (goto-char (match-end 0)))
5316 (when (looking-at "//\\([^/]+\\)/")
5317 (setq server (match-string 1))
5318 (goto-char (match-end 0)))
5321 ((looking-at "\\(.*@.*\\)")
5322 (setq message-id (match-string 1)))
5323 ((looking-at "\\([^/]+\\)/\\([-0-9]+\\)")
5324 (setq group (match-string 1)
5325 articles (split-string (match-string 2) "-")))
5326 ((looking-at "\\([^/]+\\)/?")
5327 (setq group (match-string 1)))
5329 (error "Unknown news URL syntax"))))
5330 (list scheme server group message-id articles)))
5332 (defun gnus-button-handle-news (url)
5334 (destructuring-bind (scheme server group message-id articles)
5335 (gnus-parse-news-url url)
5339 (set-buffer gnus-summary-buffer)
5341 (let ((gnus-refer-article-method (list (list 'nntp server))))
5342 (gnus-summary-refer-article message-id))
5343 (gnus-summary-refer-article message-id))))
5345 (gnus-button-fetch-group url)))))
5347 (defun gnus-button-handle-info (url)
5348 "Fetch an info URL."
5350 "^\\([^:/]+\\)?/\\(.*\\)"
5352 (gnus-info-find-node
5353 (concat "(" (or (gnus-url-unhex-string (match-string 1 url))
5356 (gnus-url-unhex-string (match-string 2 url))))
5357 (error "Can't parse %s" url)))
5359 (defun gnus-button-message-id (message-id)
5362 (set-buffer gnus-summary-buffer)
5363 (gnus-summary-refer-article message-id)))
5365 (defun gnus-button-fetch-group (address)
5366 "Fetch GROUP specified by ADDRESS."
5367 (if (not (string-match "[:/]" address))
5368 ;; This is just a simple group url.
5369 (gnus-group-read-ephemeral-group address gnus-select-method)
5372 "^\\([^:/]+\\)\\(:\\([^/]+\\)\\)?/\\([^/]+\\)\\(/\\([0-9]+\\)\\)?"
5374 (error "Can't parse %s" address)
5375 (gnus-group-read-ephemeral-group
5376 (match-string 4 address)
5377 `(nntp ,(match-string 1 address)
5378 (nntp-address ,(match-string 1 address))
5379 (nntp-port-number ,(if (match-end 3)
5380 (match-string 3 address)
5383 (and (match-end 6) (list (string-to-int (match-string 6 address))))))))
5385 (defun gnus-url-parse-query-string (query &optional downcase)
5386 (let (retval pairs cur key val)
5387 (setq pairs (split-string query "&"))
5389 (setq cur (car pairs)
5391 (if (not (string-match "=" cur))
5393 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
5394 val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
5396 (setq key (downcase key)))
5397 (setq cur (assoc key retval))
5399 (setcdr cur (cons val (cdr cur)))
5400 (setq retval (cons (list key val) retval)))))
5403 (defun gnus-url-mailto (url)
5404 ;; Send mail to someone
5405 (when (string-match "mailto:/*\\(.*\\)" url)
5406 (setq url (substring url (match-beginning 1) nil)))
5407 (let (to args subject func)
5408 (if (string-match (regexp-quote "?") url)
5409 (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
5410 args (gnus-url-parse-query-string
5411 (substring url (match-end 0) nil) t))
5412 (setq to (gnus-url-unhex-string url)))
5413 (setq args (cons (list "to" to) args)
5414 subject (cdr-safe (assoc "subject" args)))
5417 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
5420 (message-position-on-field (caar args)))
5421 (insert (mapconcat 'identity (cdar args) ", "))
5422 (setq args (cdr args)))
5425 (message-goto-subject))))
5427 (defun gnus-button-embedded-url (address)
5428 "Activate ADDRESS with `browse-url'."
5429 (browse-url (gnus-strip-whitespace address)))
5431 ;;; Next/prev buttons in the article buffer.
5433 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
5434 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
5436 (defvar gnus-prev-page-map nil)
5437 (unless gnus-prev-page-map
5438 (setq gnus-prev-page-map (make-sparse-keymap))
5439 (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
5440 (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
5442 (defun gnus-insert-prev-page-button ()
5443 (let ((buffer-read-only nil))
5445 gnus-prev-page-line-format nil
5446 `(gnus-prev t local-map ,gnus-prev-page-map
5447 gnus-callback gnus-article-button-prev-page
5448 article-type annotation))))
5450 (defvar gnus-next-page-map nil)
5451 (unless gnus-next-page-map
5452 (setq gnus-next-page-map (make-keymap))
5453 (suppress-keymap gnus-prev-page-map)
5454 (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
5455 (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
5457 (defun gnus-button-next-page ()
5458 "Go to the next page."
5460 (let ((win (selected-window)))
5461 (select-window (gnus-get-buffer-window gnus-article-buffer t))
5462 (gnus-article-next-page)
5463 (select-window win)))
5465 (defun gnus-button-prev-page ()
5466 "Go to the prev page."
5468 (let ((win (selected-window)))
5469 (select-window (gnus-get-buffer-window gnus-article-buffer t))
5470 (gnus-article-prev-page)
5471 (select-window win)))
5473 (defun gnus-insert-next-page-button ()
5474 (let ((buffer-read-only nil))
5475 (gnus-eval-format gnus-next-page-line-format nil
5477 t local-map ,gnus-next-page-map
5478 gnus-callback gnus-article-button-next-page
5479 article-type annotation))))
5481 (defun gnus-article-button-next-page (arg)
5482 "Go to the next page."
5484 (let ((win (selected-window)))
5485 (select-window (gnus-get-buffer-window gnus-article-buffer t))
5486 (gnus-article-next-page)
5487 (select-window win)))
5489 (defun gnus-article-button-prev-page (arg)
5490 "Go to the prev page."
5492 (let ((win (selected-window)))
5493 (select-window (gnus-get-buffer-window gnus-article-buffer t))
5494 (gnus-article-prev-page)
5495 (select-window win)))
5497 (defvar gnus-decode-header-methods
5498 '(mail-decode-encoded-word-region)
5499 "List of methods used to decode headers.
5501 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
5502 is FUNCTION, FUNCTION will be apply to all newsgroups. If item is a
5503 (REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
5504 whose names match REGEXP.
5507 ((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
5508 mail-decode-encoded-word-region
5509 (\"chinese\" . rfc1843-decode-region))
5512 (defvar gnus-decode-header-methods-cache nil)
5514 (defun gnus-multi-decode-header (start end)
5515 "Apply the functions from `gnus-encoded-word-methods' that match."
5516 (unless (and gnus-decode-header-methods-cache
5517 (eq gnus-newsgroup-name
5518 (car gnus-decode-header-methods-cache)))
5519 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
5522 (nconc gnus-decode-header-methods-cache (list x))
5523 (if (and gnus-newsgroup-name
5524 (string-match (car x) gnus-newsgroup-name))
5525 (nconc gnus-decode-header-methods-cache
5527 gnus-decode-header-methods))
5528 (let ((xlist gnus-decode-header-methods-cache))
5531 (narrow-to-region start end)
5533 (funcall (pop xlist) (point-min) (point-max))))))
5536 ;;; Treatment top-level handling.
5539 (defun gnus-treat-article (condition &optional part-number total-parts type)
5540 (let ((length (- (point-max) (point-min)))
5541 (alist gnus-treatment-function-alist)
5542 (article-goto-body-goes-to-point-min-p t)
5546 (let ((list gnus-article-treat-types))
5548 (when (string-match (pop list) type)
5549 (throw 'found t)))))))
5550 (highlightp (gnus-visual-p 'article-highlight 'highlight))
5552 (gnus-run-hooks 'gnus-part-display-hook)
5553 (while (setq elem (pop alist))
5556 (if (gnus-buffer-live-p gnus-summary-buffer)
5557 (set-buffer gnus-summary-buffer))
5558 (symbol-value (car elem))))
5559 (when (and (or (consp val)
5561 (gnus-treat-predicate val)
5562 (or (not (get (car elem) 'highlight))
5565 (funcall (cadr elem)))))))
5567 ;; Dynamic variables.
5569 (defvar part-number)
5570 (defvar total-parts)
5575 (defun gnus-treat-predicate (val)
5580 (stringp (car val)))
5581 (apply 'gnus-or (mapcar `(lambda (s)
5582 (string-match s ,(or gnus-newsgroup-name "")))
5585 (let ((pred (pop val)))
5588 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
5590 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
5592 (not (gnus-treat-predicate (car val))))
5594 (equal (car val) type))
5596 (error "%S is not a valid predicate" pred)))))
5604 (eq part-number total-parts))
5608 (error "%S is not a valid value" val))))
5610 (defun gnus-article-encrypt-body (protocol &optional n)
5611 "Encrypt the article body."
5614 (or gnus-article-encrypt-protocol
5615 (completing-read "Encrypt protocol: "
5616 gnus-article-encrypt-protocol-alist
5618 current-prefix-arg))
5619 (let ((func (cdr (assoc protocol gnus-article-encrypt-protocol-alist))))
5621 (error (format "Can't find the encrypt protocol %s" protocol)))
5622 (if (equal gnus-newsgroup-name "nndraft:drafts")
5623 (error "Can't encrypt the article in group nndraft:drafts"))
5624 (if (equal gnus-newsgroup-name "nndraft:queue")
5625 (error "Don't encrypt the article in group nndraft:queue"))
5626 (gnus-summary-iterate n
5628 (set-buffer gnus-summary-buffer)
5629 (let ((mail-parse-charset gnus-newsgroup-charset)
5630 (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
5631 (summary-buffer gnus-summary-buffer)
5633 (gnus-set-global-variables)
5634 (when (gnus-group-read-only-p)
5635 (error "The current newsgroup does not support article encrypt"))
5636 (gnus-summary-show-article t)
5638 (or (mail-header-references gnus-current-headers) ""))
5639 (set-buffer gnus-article-buffer)
5640 (let* ((buffer-read-only nil)
5642 (mapcar (lambda (field)
5643 (and (save-restriction
5644 (message-narrow-to-head)
5645 (goto-char (point-min))
5646 (search-forward field nil t))
5648 (message-narrow-to-field)
5649 (buffer-substring (point-min) (point-max))
5650 (delete-region (point-min) (point-max))
5652 '("Content-Type:" "Content-Transfer-Encoding:"
5653 "Content-Disposition:"))))
5654 (message-narrow-to-head)
5655 (message-remove-header "MIME-Version")
5656 (goto-char (point-max))
5657 (setq point (point))
5658 (insert (apply 'concat headers))
5660 (narrow-to-region point (point-max))
5661 (let ((message-options message-options))
5662 (message-options-set 'message-sender user-mail-address)
5663 (message-options-set 'message-recipients user-mail-address)
5664 (message-options-set 'message-sign-encrypt 'not)
5666 (goto-char (point-min))
5667 (insert "MIME-Version: 1.0\n")
5669 (gnus-summary-edit-article-done
5670 references nil summary-buffer t))
5671 (when gnus-keep-backlog
5672 (gnus-backlog-remove-article
5673 (car gnus-article-current) (cdr gnus-article-current)))
5675 (when (get-buffer gnus-original-article-buffer)
5676 (set-buffer gnus-original-article-buffer)
5677 (setq gnus-original-article nil)))
5678 (when gnus-use-cache
5679 (gnus-cache-update-article
5680 (car gnus-article-current) (cdr gnus-article-current))))))))
5682 (defvar gnus-mime-security-button-line-format "%{%([[%t:%i]%D]%)%}\n"
5683 "The following specs can be used:
5684 %t The security MIME type
5687 %D Details if button is pressed")
5689 (defvar gnus-mime-security-button-end-line-format "%{%([[End of %t]%D]%)%}\n"
5690 "The following specs can be used:
5691 %t The security MIME type
5694 %D Details if button is pressed")
5696 (defvar gnus-mime-security-button-line-format-alist
5697 '((?t gnus-tmp-type ?s)
5698 (?i gnus-tmp-info ?s)
5699 (?d gnus-tmp-details ?s)
5700 (?D gnus-tmp-pressed-details ?s)))
5702 (defvar gnus-mime-security-button-map
5703 (let ((map (make-sparse-keymap)))
5704 (unless (>= (string-to-number emacs-version) 21)
5705 (set-keymap-parent map gnus-article-mode-map))
5706 (define-key map gnus-mouse-2 'gnus-article-push-button)
5707 (define-key map "\r" 'gnus-article-press-button)
5710 (defvar gnus-mime-security-details-buffer nil)
5712 (defvar gnus-mime-security-button-pressed nil)
5714 (defvar gnus-mime-security-show-details-inline t
5715 "If non-nil, show details in the article buffer.")
5717 (defun gnus-mime-security-verify-or-decrypt (handle)
5718 (mm-remove-parts (cdr handle))
5719 (let ((region (mm-handle-multipart-ctl-parameter handle 'gnus-region))
5720 point buffer-read-only)
5722 (goto-char (car region)))
5724 (narrow-to-region (point) (point))
5725 (with-current-buffer (mm-handle-multipart-original-buffer handle)
5726 (let* ((mm-verify-option 'known)
5727 (mm-decrypt-option 'known)
5728 (nparts (mm-possibly-verify-or-decrypt (cdr handle) handle)))
5729 (unless (eq nparts (cdr handle))
5730 (mm-destroy-parts (cdr handle))
5731 (setcdr handle nparts))))
5732 (setq point (point))
5733 (gnus-mime-display-security handle)
5734 (goto-char (point-max)))
5736 (delete-region (point) (cdr region))
5737 (set-marker (car region) nil)
5738 (set-marker (cdr region) nil))
5741 (defun gnus-mime-security-show-details (handle)
5742 (let ((details (mm-handle-multipart-ctl-parameter handle 'gnus-details)))
5744 (if gnus-mime-security-show-details-inline
5745 (let ((gnus-mime-security-button-pressed t)
5746 (gnus-mime-security-button-line-format
5747 (get-text-property (point) 'gnus-line-format))
5750 (while (eq (get-text-property (point) 'gnus-line-format)
5751 gnus-mime-security-button-line-format)
5755 (narrow-to-region (point) (point))
5756 (gnus-insert-mime-security-button handle))
5757 (delete-region (point)
5758 (or (text-property-not-all
5761 gnus-mime-security-button-line-format)
5763 (if (gnus-buffer-live-p gnus-mime-security-details-buffer)
5764 (with-current-buffer gnus-mime-security-details-buffer
5767 (setq gnus-mime-security-details-buffer
5768 (gnus-get-buffer-create "*MIME Security Details*")))
5769 (with-current-buffer gnus-mime-security-details-buffer
5771 (goto-char (point-min)))
5772 (pop-to-buffer gnus-mime-security-details-buffer))
5773 (gnus-message 5 "No details."))))
5775 (defun gnus-mime-security-press-button (handle)
5776 (if (mm-handle-multipart-ctl-parameter handle 'gnus-info)
5777 (gnus-mime-security-show-details handle)
5778 (gnus-mime-security-verify-or-decrypt handle)))
5780 (defun gnus-insert-mime-security-button (handle &optional displayed)
5781 (let* ((protocol (mm-handle-multipart-ctl-parameter handle 'protocol))
5784 (or (nth 2 (assoc protocol mm-verify-function-alist))
5785 (nth 2 (assoc protocol mm-decrypt-function-alist))
5787 (if (equal (car handle) "multipart/signed")
5788 " Signed" " Encrypted")
5791 (or (mm-handle-multipart-ctl-parameter handle 'gnus-info)
5794 (mm-handle-multipart-ctl-parameter handle 'gnus-details))
5795 gnus-tmp-pressed-details
5797 (setq gnus-tmp-details
5798 (if gnus-tmp-details
5799 (concat "\n" gnus-tmp-details) ""))
5800 (setq gnus-tmp-pressed-details
5801 (if gnus-mime-security-button-pressed gnus-tmp-details ""))
5806 gnus-mime-security-button-line-format
5807 gnus-mime-security-button-line-format-alist
5808 `(keymap ,gnus-mime-security-button-map
5809 ,@(if (>= (string-to-number emacs-version) 21)
5810 nil ;; XEmacs doesn't care
5811 (list 'local-map gnus-mime-security-button-map))
5812 gnus-callback gnus-mime-security-press-button
5813 gnus-line-format ,gnus-mime-security-button-line-format
5814 article-type annotation
5817 (widget-convert-button
5820 :action 'gnus-widget-press-button
5821 :button-keymap gnus-mime-security-button-map
5823 (lambda (widget/window &optional overlay pos)
5824 ;; Needed to properly clear the message due to a bug in
5825 ;; wid-edit (XEmacs only).
5826 (if (boundp 'help-echo-owns-message)
5827 (setq help-echo-owns-message t))
5830 (aref gnus-mouse-2 0))))))
5832 (defun gnus-mime-display-security (handle)
5834 (narrow-to-region (point) (point))
5835 (unless (gnus-unbuttonized-mime-type-p (car handle))
5836 (gnus-insert-mime-security-button handle))
5837 (gnus-mime-display-mixed (cdr handle))
5840 (unless (gnus-unbuttonized-mime-type-p (car handle))
5841 (let ((gnus-mime-security-button-line-format
5842 gnus-mime-security-button-end-line-format))
5843 (gnus-insert-mime-security-button handle)))
5844 (mm-set-handle-multipart-parameter
5846 (cons (set-marker (make-marker) (point-min))
5847 (set-marker (make-marker) (point-max))))))
5853 (run-hooks 'gnus-art-load-hook)
5855 ;;; gnus-art.el ends here