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))
42 (autoload 'gnus-msg-mail "gnus-msg" nil t)
43 (autoload 'gnus-button-mailto "gnus-msg")
44 (autoload 'gnus-button-reply "gnus-msg" nil t)
46 (defgroup gnus-article nil
48 :link '(custom-manual "(gnus)The Article Buffer")
51 (defgroup gnus-article-treat nil
52 "Treating article parts."
53 :link '(custom-manual "(gnus)Article Hiding")
56 (defgroup gnus-article-hiding nil
57 "Hiding article parts."
58 :link '(custom-manual "(gnus)Article Hiding")
61 (defgroup gnus-article-highlight nil
62 "Article highlighting."
63 :link '(custom-manual "(gnus)Article Highlighting")
67 (defgroup gnus-article-signature nil
69 :link '(custom-manual "(gnus)Article Signature")
72 (defgroup gnus-article-headers nil
74 :link '(custom-manual "(gnus)Hiding Headers")
77 (defgroup gnus-article-washing nil
78 "Special commands on articles."
79 :link '(custom-manual "(gnus)Article Washing")
82 (defgroup gnus-article-emphasis nil
83 "Fontisizing articles."
84 :link '(custom-manual "(gnus)Article Fontisizing")
87 (defgroup gnus-article-saving nil
89 :link '(custom-manual "(gnus)Saving Articles")
92 (defgroup gnus-article-mime nil
93 "Worshiping the MIME wonder."
94 :link '(custom-manual "(gnus)Using MIME")
97 (defgroup gnus-article-buttons nil
98 "Pushable buttons in the article buffer."
99 :link '(custom-manual "(gnus)Article Buttons")
100 :group 'gnus-article)
102 (defgroup gnus-article-various nil
103 "Other article options."
104 :link '(custom-manual "(gnus)Misc Article")
105 :group 'gnus-article)
107 (defcustom gnus-ignored-headers
108 '("^Path:" "^Expires:" "^Date-Received:" "^References:" "^Xref:" "^Lines:"
109 "^Relay-Version:" "^Message-ID:" "^Approved:" "^Sender:" "^Received:"
110 "^X-UIDL:" "^MIME-Version:" "^Return-Path:" "^In-Reply-To:"
111 "^Content-Type:" "^Content-Transfer-Encoding:" "^X-WebTV-Signature:"
112 "^X-MimeOLE:" "^X-MSMail-Priority:" "^X-Priority:" "^X-Loop:"
113 "^X-Authentication-Warning:" "^X-MIME-Autoconverted:" "^X-Face:"
114 "^X-Attribution:" "^X-Originating-IP:" "^Delivered-To:"
115 "^NNTP-[-A-Za-z]+:" "^Distribution:" "^X-no-archive:" "^X-Trace:"
116 "^X-Complaints-To:" "^X-NNTP-Posting-Host:" "^X-Orig.*:"
117 "^Abuse-Reports-To:" "^Cache-Post-Path:" "^X-Article-Creation-Date:"
118 "^X-Poster:" "^X-Mail2News-Path:" "^X-Server-Date:" "^X-Cache:"
119 "^Originator:" "^X-Problems-To:" "^X-Auth-User:" "^X-Post-Time:"
120 "^X-Admin:" "^X-UID:" "^Resent-[-A-Za-z]+:" "^X-Mailing-List:"
121 "^Precedence:" "^Original-[-A-Za-z]+:" "^X-filename:" "^X-Orcpt:"
122 "^Old-Received:" "^X-Pgp" "^X-Auth:" "^X-From-Line:"
123 "^X-Gnus-Article-Number:" "^X-Majordomo:" "^X-Url:" "^X-Sender:"
124 "^MBOX-Line" "^Priority:" "^X400-[-A-Za-z]+:"
125 "^Status:" "^X-Gnus-Mail-Source:" "^Cancel-Lock:"
126 "^X-FTN" "^X-EXP32-SerialNo:" "^Encoding:" "^Importance:"
127 "^Autoforwarded:" "^Original-Encoded-Information-Types:" "^X-Ya-Pop3:"
128 "^X-Face-Version:" "^X-Vms-To:" "^X-ML-NAME:" "^X-ML-COUNT:"
129 "^Mailing-List:" "^X-finfo:" "^X-md5sum:" "^X-md5sum-Origin:"
130 "^X-Sun-Charset:" "^X-Accept-Language:" "^X-Envelope-Sender:"
131 "^List-[A-Za-z]+:" "^X-Listprocessor-Version:"
132 "^X-Received:" "^X-Distribute:" "^X-Sequence:" "^X-Juno-Line-Breaks:"
133 "^X-Notes-Item:" "^X-MS-TNEF-Correlator:" "^x-uunet-gateway:"
134 "^X-Received:" "^Content-length:" "X-precedence:"
135 "^X-Authenticated-User:" "^X-Comment" "^X-Report:" "^X-Abuse-Info:"
136 "^X-HTTP-Proxy:" "^X-Mydeja-Info:" "^X-Copyright" "^X-No-Markup:"
138 "*All headers that start with this regexp will be hidden.
139 This variable can also be a list of regexps of headers to be ignored.
140 If `gnus-visible-headers' is non-nil, this variable will be ignored."
141 :type '(choice :custom-show nil
144 :group 'gnus-article-hiding)
146 (defcustom gnus-visible-headers
147 "^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:"
148 "*All headers that do not match this regexp will be hidden.
149 This variable can also be a list of regexp of headers to remain visible.
150 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
151 :type '(repeat :value-to-internal (lambda (widget value)
152 (custom-split-regexp-maybe value))
153 :match (lambda (widget value)
155 (widget-editable-list-match widget value)))
157 :group 'gnus-article-hiding)
159 (defcustom gnus-sorted-header-list
160 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
161 "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
162 "*This variable is a list of regular expressions.
163 If it is non-nil, headers that match the regular expressions will
164 be placed first in the article buffer in the sequence specified by
166 :type '(repeat regexp)
167 :group 'gnus-article-hiding)
169 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
170 "Headers that are only to be displayed if they have interesting data.
171 Possible values in this list are:
173 'empty Headers with no content.
174 'newsgroups Newsgroup identical to Gnus group.
175 'to-address To identical to To-address.
176 'followup-to Followup-to identical to Newsgroups.
177 'reply-to Reply-to identical to From.
178 'date Date less than four days old.
179 'long-to To and/or Cc longer than 1024 characters.
180 'many-to Multiple To and/or Cc."
181 :type '(set (const :tag "Headers with no content." empty)
182 (const :tag "Newsgroups identical to Gnus group." newsgroups)
183 (const :tag "To identical to To-address." to-address)
184 (const :tag "Followup-to identical to Newsgroups." followup-to)
185 (const :tag "Reply-to identical to From." reply-to)
186 (const :tag "Date less than four days old." date)
187 (const :tag "To and/or Cc longer than 1024 characters." long-to)
188 (const :tag "Multiple To and/or Cc headers." many-to))
189 :group 'gnus-article-hiding)
191 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
192 "Regexp matching signature separator.
193 This can also be a list of regexps. In that case, it will be checked
194 from head to tail looking for a separator. Searches will be done from
195 the end of the buffer."
196 :type '(repeat string)
197 :group 'gnus-article-signature)
199 (defcustom gnus-signature-limit nil
200 "Provide a limit to what is considered a signature.
201 If it is a number, no signature may not be longer (in characters) than
202 that number. If it is a floating point number, no signature may be
203 longer (in lines) than that number. If it is a function, the function
204 will be called without any parameters, and if it returns nil, there is
205 no signature in the buffer. If it is a string, it will be used as a
206 regexp. If it matches, the text in question is not a signature."
207 :type '(choice (integer :value 200)
209 (function :value fun)
210 (regexp :value ".*"))
211 :group 'gnus-article-signature)
213 (defcustom gnus-hidden-properties '(invisible t intangible t)
214 "Property list to use for hiding text."
216 :group 'gnus-article-hiding)
218 ;; Fixme: This isn't the right thing for mixed graphical and and
219 ;; non-graphical frames in a session.
220 ;; gnus-xmas.el overrides this for XEmacs.
221 (defcustom gnus-article-x-face-command
222 (if (and (fboundp 'image-type-available-p)
223 (image-type-available-p 'xbm))
224 'gnus-article-display-xface
225 (if gnus-article-compface-xbm
226 "{ echo '/* Width=48, Height=48 */'; uncompface; } | display -"
227 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | \
229 "*String or function to be executed to display an X-Face header.
230 If it is a string, the command will be executed in a sub-shell
231 asynchronously. The compressed face will be piped to this command."
232 :type '(choice string
233 (function-item gnus-article-display-xface)
236 :group 'gnus-article-washing)
238 (defcustom gnus-article-x-face-too-ugly nil
239 "Regexp matching posters whose face shouldn't be shown automatically."
240 :type '(choice regexp (const nil))
241 :group 'gnus-article-washing)
243 (defcustom gnus-article-banner-alist nil
244 "Banner alist for stripping.
246 ((egroups . \"^[ \\t\\n]*-------------------+\\\\( \\\\(e\\\\|Yahoo! \\\\)Groups Sponsor -+\\\\)?....\\n\\\\(.+\\n\\\\)+\"))"
248 :type '(repeat (cons symbol regexp))
249 :group 'gnus-article-washing)
251 (gnus-define-group-parameter
254 "Alist of regexps (to match group names) and banner."
255 :variable-group gnus-article-washing
257 '(choice :tag "Banner"
259 (const :tag "Remove signature" signature)
260 (symbol :tag "Item in `gnus-article-banner-alist'" none)
262 (const :tag "None" nil))
264 "If non-nil, specify how to remove `banners' from articles.
266 Symbol `signature' means to remove signatures delimited by
267 `gnus-signature-separator'. Any other symbol is used to look up a
268 regular expression to match the banner in `gnus-article-banner-alist'.
269 A string is used as a regular expression to match the banner
272 (defcustom gnus-emphasis-alist
274 "\\(\\s-\\|^\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\\(\\s-\\|[-,;:\"]\\s-\\|[?!.]+\\s-\\|\\s)\\)")
276 '(("_" "_" underline)
279 ("_/" "/_" underline-italic)
280 ("_\\*" "\\*_" underline-bold)
281 ("\\*/" "/\\*" bold-italic)
282 ("_\\*/" "/\\*_" underline-bold-italic))))
283 `(("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
284 2 3 gnus-emphasis-underline)
288 (format format (car spec) (cadr spec))
289 2 3 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
291 "*Alist that says how to fontify certain phrases.
292 Each item looks like this:
294 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
296 The first element is a regular expression to be matched. The second
297 is a number that says what regular expression grouping used to find
298 the entire emphasized word. The third is a number that says what
299 regexp grouping should be displayed and highlighted. The fourth
300 is the face used for highlighting."
301 :type '(repeat (list :value ("" 0 0 default)
303 (integer :tag "Match group")
304 (integer :tag "Emphasize group")
306 :group 'gnus-article-emphasis)
308 (defcustom gnus-emphasize-whitespace-regexp "^[ \t]+\\|[ \t]*\n"
309 "A regexp to describe whitespace which should not be emphasized.
310 Typical values are \"^[ \\t]+\\\\|[ \\t]*\\n\" and \"[ \\t]+\\\\|[ \\t]*\\n\".
311 The former avoids underlining of leading and trailing whitespace,
312 and the latter avoids underlining any whitespace at all."
314 :group 'gnus-article-emphasis
317 (defface gnus-emphasis-bold '((t (:bold t)))
318 "Face used for displaying strong emphasized text (*word*)."
319 :group 'gnus-article-emphasis)
321 (defface gnus-emphasis-italic '((t (:italic t)))
322 "Face used for displaying italic emphasized text (/word/)."
323 :group 'gnus-article-emphasis)
325 (defface gnus-emphasis-underline '((t (:underline t)))
326 "Face used for displaying underlined emphasized text (_word_)."
327 :group 'gnus-article-emphasis)
329 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
330 "Face used for displaying underlined bold emphasized text (_*word*_)."
331 :group 'gnus-article-emphasis)
333 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
334 "Face used for displaying underlined italic emphasized text (_/word/_)."
335 :group 'gnus-article-emphasis)
337 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
338 "Face used for displaying bold italic emphasized text (/*word*/)."
339 :group 'gnus-article-emphasis)
341 (defface gnus-emphasis-underline-bold-italic
342 '((t (:bold t :italic t :underline t)))
343 "Face used for displaying underlined bold italic emphasized text.
344 Esample: (_/*word*/_)."
345 :group 'gnus-article-emphasis)
347 (defface gnus-emphasis-highlight-words
348 '((t (:background "black" :foreground "yellow")))
349 "Face used for displaying highlighted words."
350 :group 'gnus-article-emphasis)
352 (defcustom gnus-article-time-format "%a, %b %d %Y %T %Z"
353 "Format for display of Date headers in article bodies.
354 See `format-time-string' for the possible values.
356 The variable can also be function, which should return a complete Date
357 header. The function is called with one argument, the time, which can
358 be fed to `format-time-string'."
359 :type '(choice string symbol)
360 :link '(custom-manual "(gnus)Article Date")
361 :group 'gnus-article-washing)
364 (autoload 'mail-extract-address-components "mail-extr"))
366 (defcustom gnus-save-all-headers t
367 "*If non-nil, don't remove any headers before saving."
368 :group 'gnus-article-saving
371 (defcustom gnus-prompt-before-saving 'always
372 "*This variable says how much prompting is to be done when saving articles.
373 If it is nil, no prompting will be done, and the articles will be
374 saved to the default files. If this variable is `always', each and
375 every article that is saved will be preceded by a prompt, even when
376 saving large batches of articles. If this variable is neither nil not
377 `always', there the user will be prompted once for a file name for
378 each invocation of the saving commands."
379 :group 'gnus-article-saving
380 :type '(choice (item always)
381 (item :tag "never" nil)
382 (sexp :tag "once" :format "%t\n" :value t)))
384 (defcustom gnus-saved-headers gnus-visible-headers
385 "Headers to keep if `gnus-save-all-headers' is nil.
386 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
387 If that variable is nil, however, all headers that match this regexp
388 will be kept while the rest will be deleted before saving."
389 :group 'gnus-article-saving
392 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
393 "A function to save articles in your favourite format.
394 The function must be interactively callable (in other words, it must
395 be an Emacs command).
397 Gnus provides the following functions:
399 * gnus-summary-save-in-rmail (Rmail format)
400 * gnus-summary-save-in-mail (Unix mail format)
401 * gnus-summary-save-in-folder (MH folder)
402 * gnus-summary-save-in-file (article format)
403 * gnus-summary-save-in-vm (use VM's folder format)
404 * gnus-summary-write-to-file (article format -- overwrite)."
405 :group 'gnus-article-saving
406 :type '(radio (function-item gnus-summary-save-in-rmail)
407 (function-item gnus-summary-save-in-mail)
408 (function-item gnus-summary-save-in-folder)
409 (function-item gnus-summary-save-in-file)
410 (function-item gnus-summary-save-in-vm)
411 (function-item gnus-summary-write-to-file)))
413 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
414 "A function generating a file name to save articles in Rmail format.
415 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
416 :group 'gnus-article-saving
419 (defcustom gnus-mail-save-name 'gnus-plain-save-name
420 "A function generating a file name to save articles in Unix mail format.
421 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
422 :group 'gnus-article-saving
425 (defcustom gnus-folder-save-name 'gnus-folder-save-name
426 "A function generating a file name to save articles in MH folder.
427 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
428 :group 'gnus-article-saving
431 (defcustom gnus-file-save-name 'gnus-numeric-save-name
432 "A function generating a file name to save articles in article format.
433 The function is called with NEWSGROUP, HEADERS, and optional
435 :group 'gnus-article-saving
438 (defcustom gnus-split-methods
439 '((gnus-article-archive-name)
440 (gnus-article-nndoc-name))
441 "*Variable used to suggest where articles are to be saved.
442 For instance, if you would like to save articles related to Gnus in
443 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
444 you could set this variable to something like:
446 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
447 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
449 This variable is an alist where the where the key is the match and the
450 value is a list of possible files to save in if the match is non-nil.
452 If the match is a string, it is used as a regexp match on the
453 article. If the match is a symbol, that symbol will be funcalled
454 from the buffer of the article to be saved with the newsgroup as the
455 parameter. If it is a list, it will be evaled in the same buffer.
457 If this form or function returns a string, this string will be used as
458 a possible file name; and if it returns a non-nil list, that list will
459 be used as possible file names."
460 :group 'gnus-article-saving
461 :type '(repeat (choice (list :value (fun) function)
462 (cons :value ("" "") regexp (repeat string))
465 (defcustom gnus-page-delimiter "^\^L"
466 "*Regexp describing what to use as article page delimiters.
467 The default value is \"^\^L\", which is a form linefeed at the
468 beginning of a line."
470 :group 'gnus-article-various)
472 (defcustom gnus-article-mode-line-format "Gnus: %g [%w] %S%m"
473 "*The format specification for the article mode line.
474 See `gnus-summary-mode-line-format' for a closer description.
476 The following additional specs are available:
478 %w The article washing status.
479 %m The number of MIME parts in the article."
481 :group 'gnus-article-various)
483 (defcustom gnus-article-mode-hook nil
484 "*A hook for Gnus article mode."
486 :group 'gnus-article-various)
488 (when (featurep 'xemacs)
489 ;; Extracted from gnus-xmas-define in order to preserve user settings
490 (when (fboundp 'turn-off-scroll-in-place)
491 (add-hook 'gnus-article-mode-hook 'turn-off-scroll-in-place))
492 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
493 (add-hook 'gnus-article-mode-hook 'gnus-xmas-article-menu-add))
495 (defcustom gnus-article-menu-hook nil
496 "*Hook run after the creation of the article mode menu."
498 :group 'gnus-article-various)
500 (defcustom gnus-article-prepare-hook nil
501 "*A hook called after an article has been prepared in the article buffer."
503 :group 'gnus-article-various)
505 (defcustom gnus-article-hide-pgp-hook nil
506 "*A hook called after successfully hiding a PGP signature."
508 :group 'gnus-article-various)
510 (defcustom gnus-article-button-face 'bold
511 "Face used for highlighting buttons in the article buffer.
513 An article button is a piece of text that you can activate by pressing
514 `RET' or `mouse-2' above it."
516 :group 'gnus-article-buttons)
518 (defcustom gnus-article-mouse-face 'highlight
519 "Face used for mouse highlighting in the article buffer.
521 Article buttons will be displayed in this face when the cursor is
524 :group 'gnus-article-buttons)
526 (defcustom gnus-signature-face 'gnus-signature-face
527 "Face used for highlighting a signature in the article buffer.
528 Obsolete; use the face `gnus-signature-face' for customizations instead."
530 :group 'gnus-article-highlight
531 :group 'gnus-article-signature)
533 (defface gnus-signature-face
536 "Face used for highlighting a signature in the article buffer."
537 :group 'gnus-article-highlight
538 :group 'gnus-article-signature)
540 (defface gnus-header-from-face
543 (:foreground "spring green"))
546 (:foreground "red3"))
549 "Face used for displaying from headers."
550 :group 'gnus-article-headers
551 :group 'gnus-article-highlight)
553 (defface gnus-header-subject-face
556 (:foreground "SeaGreen3"))
559 (:foreground "red4"))
561 (:bold t :italic t)))
562 "Face used for displaying subject headers."
563 :group 'gnus-article-headers
564 :group 'gnus-article-highlight)
566 (defface gnus-header-newsgroups-face
569 (:foreground "yellow" :italic t))
572 (:foreground "MidnightBlue" :italic t))
575 "Face used for displaying newsgroups headers."
576 :group 'gnus-article-headers
577 :group 'gnus-article-highlight)
579 (defface gnus-header-name-face
582 (:foreground "SeaGreen"))
585 (:foreground "maroon"))
588 "Face used for displaying header names."
589 :group 'gnus-article-headers
590 :group 'gnus-article-highlight)
592 (defface gnus-header-content-face
595 (:foreground "forest green" :italic t))
598 (:foreground "indianred4" :italic t))
600 (:italic t))) "Face used for displaying header content."
601 :group 'gnus-article-headers
602 :group 'gnus-article-highlight)
604 (defcustom gnus-header-face-alist
605 '(("From" nil gnus-header-from-face)
606 ("Subject" nil gnus-header-subject-face)
607 ("Newsgroups:.*," nil gnus-header-newsgroups-face)
608 ("" gnus-header-name-face gnus-header-content-face))
609 "*Controls highlighting of article header.
611 An alist of the form (HEADER NAME CONTENT).
613 HEADER is a regular expression which should match the name of an
614 header header and NAME and CONTENT are either face names or nil.
616 The name of each header field will be displayed using the face
617 specified by the first element in the list where HEADER match the
618 header name and NAME is non-nil. Similarly, the content will be
619 displayed by the first non-nil matching CONTENT face."
620 :group 'gnus-article-headers
621 :group 'gnus-article-highlight
622 :type '(repeat (list (regexp :tag "Header")
624 (item :tag "skip" nil)
625 (face :value default))
626 (choice :tag "Content"
627 (item :tag "skip" nil)
628 (face :value default)))))
630 (defcustom gnus-article-decode-hook
631 '(article-decode-charset article-decode-encoded-words)
632 "*Hook run to decode charsets in articles."
633 :group 'gnus-article-headers
636 (defcustom gnus-display-mime-function 'gnus-display-mime
637 "Function to display MIME articles."
638 :group 'gnus-article-mime
641 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
642 "Function used to decode headers.")
644 (defvar gnus-article-dumbquotes-map
663 "Table for MS-to-Latin1 translation.")
665 (defcustom gnus-ignored-mime-types nil
666 "List of MIME types that should be ignored by Gnus."
668 :group 'gnus-article-mime
669 :type '(repeat regexp))
671 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
672 "List of MIME types that should not be given buttons when rendered inline."
674 :group 'gnus-article-mime
675 :type '(repeat regexp))
677 (defcustom gnus-article-mime-part-function nil
678 "Function called with a MIME handle as the argument.
679 This is meant for people who want to do something automatic based
680 on parts -- for instance, adding Vcard info to a database."
681 :group 'gnus-article-mime
684 (defcustom gnus-mime-multipart-functions nil
685 "An alist of MIME types to functions to display them."
687 :group 'gnus-article-mime
690 (defcustom gnus-article-date-lapsed-new-header nil
691 "Whether the X-Sent and Date headers can coexist.
692 When using `gnus-treat-date-lapsed', the \"X-Sent:\" header will
693 either replace the old \"Date:\" header (if this variable is nil), or
694 be added below it (otherwise)."
696 :group 'gnus-article-headers
699 (defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
700 "Function called with a MIME handle as the argument.
701 This is meant for people who want to view first matched part.
702 For `undisplayed-alternative' (default), the first undisplayed
703 part or alternative part is used. For `undisplayed', the first
704 undisplayed part is used. For a function, the first part which
705 the function return `t' is used. For `nil', the first part is
708 :group 'gnus-article-mime
710 (item :tag "first" :value nil)
711 (item :tag "undisplayed" :value undisplayed)
712 (item :tag "undisplayed or alternative"
713 :value undisplayed-alternative)
716 (defcustom gnus-mime-action-alist
717 '(("save to file" . gnus-mime-save-part)
718 ("save and strip" . gnus-mime-save-part-and-strip)
719 ("display as text" . gnus-mime-inline-part)
720 ("view the part" . gnus-mime-view-part)
721 ("pipe to command" . gnus-mime-pipe-part)
722 ("toggle display" . gnus-article-press-button)
723 ("toggle display" . gnus-article-view-part-as-charset)
724 ("view as type" . gnus-mime-view-part-as-type)
725 ("internalize type" . gnus-mime-internalize-part)
726 ("externalize type" . gnus-mime-externalize-part))
727 "An alist of actions that run on the MIME attachment."
728 :group 'gnus-article-mime
729 :type '(repeat (cons (string :tag "name")
732 (defcustom gnus-mime-action-alist
733 '(("save to file" . gnus-mime-save-part)
734 ("display as text" . gnus-mime-inline-part)
735 ("view the part" . gnus-mime-view-part)
736 ("pipe to command" . gnus-mime-pipe-part)
737 ("toggle display" . gnus-article-press-button)
738 ("view as type" . gnus-mime-view-part-as-type)
739 ("internalize type" . gnus-mime-internalize-part)
740 ("externalize type" . gnus-mime-externalize-part))
741 "An alist of actions that run on the MIME attachment."
743 :group 'gnus-article-mime
744 :type '(repeat (cons (string :tag "name")
748 ;;; The treatment variables
751 (defvar gnus-part-display-hook nil
752 "Hook called on parts that are to receive treatment.")
754 (defvar gnus-article-treat-custom
755 '(choice (const :tag "Off" nil)
757 (const :tag "Header" head)
758 (const :tag "Last" last)
759 (integer :tag "Less")
760 (repeat :tag "Groups" regexp)
761 (sexp :tag "Predicate")))
763 (defvar gnus-article-treat-head-custom
764 '(choice (const :tag "Off" nil)
765 (const :tag "Header" head)))
767 (defvar gnus-article-treat-types '("text/plain")
770 (defvar gnus-inhibit-treatment nil
771 "Whether to inhibit treatment.")
773 (defcustom gnus-treat-highlight-signature '(or last (typep "text/x-vcard"))
774 "Highlight the signature.
775 Valid values are nil, t, `head', `last', an integer or a predicate.
776 See the manual for details."
777 :group 'gnus-article-treat
778 :type gnus-article-treat-custom)
779 (put 'gnus-treat-highlight-signature 'highlight t)
781 (defcustom gnus-treat-buttonize 100000
783 Valid values are nil, t, `head', `last', an integer or a predicate.
784 See the manual for details."
785 :group 'gnus-article-treat
786 :type gnus-article-treat-custom)
787 (put 'gnus-treat-buttonize 'highlight t)
789 (defcustom gnus-treat-buttonize-head 'head
790 "Add buttons to the head.
791 Valid values are nil, t, `head', `last', an integer or a predicate.
792 See the manual for details."
793 :group 'gnus-article-treat
794 :type gnus-article-treat-head-custom)
795 (put 'gnus-treat-buttonize-head 'highlight t)
797 (defcustom gnus-treat-emphasize
798 (and (or window-system
800 (>= (string-to-number emacs-version) 21))
803 Valid values are nil, t, `head', `last', an integer or a predicate.
804 See the manual for details."
805 :group 'gnus-article-treat
806 :type gnus-article-treat-custom)
807 (put 'gnus-treat-emphasize 'highlight t)
809 (defcustom gnus-treat-strip-cr nil
810 "Remove carriage returns.
811 Valid values are nil, t, `head', `last', an integer or a predicate.
812 See the manual for details."
813 :group 'gnus-article-treat
814 :type gnus-article-treat-custom)
816 (defcustom gnus-treat-leading-whitespace nil
817 "Remove leading whitespace in headers.
818 Valid values are nil, t, `head', `last', an integer or a predicate.
819 See the manual for details."
820 :group 'gnus-article-treat
821 :type gnus-article-treat-custom)
823 (defcustom gnus-treat-hide-headers 'head
825 Valid values are nil, t, `head', `last', an integer or a predicate.
826 See the manual for details."
827 :group 'gnus-article-treat
828 :type gnus-article-treat-head-custom)
830 (defcustom gnus-treat-hide-boring-headers nil
831 "Hide boring headers.
832 Valid values are nil, t, `head', `last', an integer or a predicate.
833 See the manual for details."
834 :group 'gnus-article-treat
835 :type gnus-article-treat-head-custom)
837 (defcustom gnus-treat-hide-signature nil
839 Valid values are nil, t, `head', `last', an integer or a predicate.
840 See the manual for details."
841 :group 'gnus-article-treat
842 :type gnus-article-treat-custom)
844 (defcustom gnus-treat-fill-article nil
846 Valid values are nil, t, `head', `last', an integer or a predicate.
847 See the manual for details."
848 :group 'gnus-article-treat
849 :type gnus-article-treat-custom)
851 (defcustom gnus-treat-hide-citation nil
853 Valid values are nil, t, `head', `last', an integer or a predicate.
854 See the manual for details."
855 :group 'gnus-article-treat
856 :type gnus-article-treat-custom)
858 (defcustom gnus-treat-hide-citation-maybe nil
860 Valid values are nil, t, `head', `last', an integer or a predicate.
861 See the manual for details."
862 :group 'gnus-article-treat
863 :type gnus-article-treat-custom)
865 (defcustom gnus-treat-hide-citation-maybe nil
867 Valid values are nil, t, `head', `last', an integer or a predicate.
868 See the manual for details."
869 :group 'gnus-article-treat
870 :type gnus-article-treat-custom)
872 (defcustom gnus-treat-strip-list-identifiers 'head
873 "Strip list identifiers from `gnus-list-identifiers`.
874 Valid values are nil, t, `head', `last', an integer or a predicate.
875 See the manual for details."
877 :group 'gnus-article-treat
878 :type gnus-article-treat-custom)
880 (defcustom gnus-treat-strip-pgp t
881 "Strip PGP signatures.
882 Valid values are nil, t, `head', `last', an integer or a predicate.
883 See the manual for details."
884 :group 'gnus-article-treat
885 :type gnus-article-treat-custom)
887 (defcustom gnus-treat-strip-pem nil
888 "Strip PEM signatures.
889 Valid values are nil, t, `head', `last', an integer or a predicate.
890 See the manual for details."
891 :group 'gnus-article-treat
892 :type gnus-article-treat-custom)
894 (defcustom gnus-treat-strip-banner t
895 "Strip banners from articles.
896 The banner to be stripped is specified in the `banner' group parameter.
897 Valid values are nil, t, `head', `last', an integer or a predicate.
898 See the manual for details."
899 :group 'gnus-article-treat
900 :type gnus-article-treat-custom)
902 (defcustom gnus-treat-highlight-headers 'head
903 "Highlight the headers.
904 Valid values are nil, t, `head', `last', an integer or a predicate.
905 See the manual for details."
906 :group 'gnus-article-treat
907 :type gnus-article-treat-head-custom)
908 (put 'gnus-treat-highlight-headers 'highlight t)
910 (defcustom gnus-treat-highlight-citation t
911 "Highlight cited text.
912 Valid values are nil, t, `head', `last', an integer or a predicate.
913 See the manual for details."
914 :group 'gnus-article-treat
915 :type gnus-article-treat-custom)
916 (put 'gnus-treat-highlight-citation 'highlight t)
918 (defcustom gnus-treat-date-ut nil
919 "Display the Date in UT (GMT).
920 Valid values are nil, t, `head', `last', an integer or a predicate.
921 See the manual for details."
922 :group 'gnus-article-treat
923 :type gnus-article-treat-head-custom)
925 (defcustom gnus-treat-date-local nil
926 "Display the Date in the local timezone.
927 Valid values are nil, t, `head', `last', an integer or a predicate.
928 See the manual for details."
929 :group 'gnus-article-treat
930 :type gnus-article-treat-head-custom)
932 (defcustom gnus-treat-date-english nil
933 "Display the Date in a format that can be read aloud in English.
934 Valid values are nil, t, `head', `last', an integer or a predicate.
935 See the manual for details."
936 :group 'gnus-article-treat
937 :type gnus-article-treat-head-custom)
939 (defcustom gnus-treat-date-lapsed nil
940 "Display the Date header in a way that says how much time has elapsed.
941 Valid values are nil, t, `head', `last', an integer or a predicate.
942 See the manual for details."
943 :group 'gnus-article-treat
944 :type gnus-article-treat-head-custom)
946 (defcustom gnus-treat-date-original nil
947 "Display the date in the original timezone.
948 Valid values are nil, t, `head', `last', an integer or a predicate.
949 See the manual for details."
950 :group 'gnus-article-treat
951 :type gnus-article-treat-head-custom)
953 (defcustom gnus-treat-date-iso8601 nil
954 "Display the date in the ISO8601 format.
955 Valid values are nil, t, `head', `last', an integer or a predicate.
956 See the manual for details."
958 :group 'gnus-article-treat
959 :type gnus-article-treat-head-custom)
961 (defcustom gnus-treat-date-user-defined nil
962 "Display the date in a user-defined format.
963 The format is defined by the `gnus-article-time-format' variable.
964 Valid values are nil, t, `head', `last', an integer or a predicate.
965 See the manual for details."
966 :group 'gnus-article-treat
967 :type gnus-article-treat-head-custom)
969 (defcustom gnus-treat-strip-headers-in-body t
970 "Strip the X-No-Archive header line from the beginning of the body.
971 Valid values are nil, t, `head', `last', an integer or a predicate.
972 See the manual for details."
974 :group 'gnus-article-treat
975 :type gnus-article-treat-custom)
977 (defcustom gnus-treat-strip-trailing-blank-lines nil
978 "Strip trailing blank lines.
979 Valid values are nil, t, `head', `last', an integer or a predicate.
980 See the manual for details."
981 :group 'gnus-article-treat
982 :type gnus-article-treat-custom)
984 (defcustom gnus-treat-strip-leading-blank-lines nil
985 "Strip leading blank lines.
986 Valid values are nil, t, `head', `last', an integer or a predicate.
987 See the manual for details."
988 :group 'gnus-article-treat
989 :type gnus-article-treat-custom)
991 (defcustom gnus-treat-strip-multiple-blank-lines nil
992 "Strip multiple blank lines.
993 Valid values are nil, t, `head', `last', an integer or a predicate.
994 See the manual for details."
995 :group 'gnus-article-treat
996 :type gnus-article-treat-custom)
998 (defcustom gnus-treat-overstrike t
999 "Treat overstrike highlighting.
1000 Valid values are nil, t, `head', `last', an integer or a predicate.
1001 See the manual for details."
1002 :group 'gnus-article-treat
1003 :type gnus-article-treat-custom)
1004 (put 'gnus-treat-overstrike 'highlight t)
1006 (defcustom gnus-treat-display-xface
1007 (and (or (and (fboundp 'image-type-available-p)
1008 (image-type-available-p 'xbm)
1009 (string-match "^0x" (shell-command-to-string "uncompface")))
1010 (and (featurep 'xemacs) (featurep 'xface)))
1012 "Display X-Face headers.
1013 Valid values are nil, t, `head', `last', an integer or a predicate.
1014 See the manual for details."
1015 :group 'gnus-article-treat
1017 :type gnus-article-treat-head-custom)
1018 (put 'gnus-treat-display-xface 'highlight t)
1020 (defcustom gnus-treat-display-smileys
1021 (if (or (and (featurep 'xemacs)
1023 (and (fboundp 'image-type-available-p)
1024 (image-type-available-p 'pbm)))
1027 Valid values are nil, t, `head', `last', an integer or a predicate.
1028 See the manual for details."
1029 :group 'gnus-article-treat
1031 :type gnus-article-treat-custom)
1032 (put 'gnus-treat-display-smileys 'highlight t)
1034 (defcustom gnus-treat-display-picons (if (featurep 'xemacs) 'head nil)
1036 Valid values are nil, t, `head', `last', an integer or a predicate.
1037 See the manual for details."
1038 :group 'gnus-article-treat
1039 :type gnus-article-treat-head-custom)
1040 (put 'gnus-treat-display-picons 'highlight t)
1042 (defcustom gnus-treat-capitalize-sentences nil
1043 "Capitalize sentence-starting words.
1044 Valid values are nil, t, `head', `last', an integer or a predicate.
1045 See the manual for details."
1047 :group 'gnus-article-treat
1048 :type gnus-article-treat-custom)
1050 (defcustom gnus-treat-fill-long-lines nil
1052 Valid values are nil, t, `head', `last', an integer or a predicate.
1053 See the manual for details."
1054 :group 'gnus-article-treat
1055 :type gnus-article-treat-custom)
1057 (defcustom gnus-treat-play-sounds nil
1059 Valid values are nil, t, `head', `last', an integer or a predicate.
1060 See the manual for details."
1062 :group 'gnus-article-treat
1063 :type gnus-article-treat-custom)
1065 (defcustom gnus-treat-translate nil
1066 "Translate articles from one language to another.
1067 Valid values are nil, t, `head', `last', an integer or a predicate.
1068 See the manual for details."
1070 :group 'gnus-article-treat
1071 :type gnus-article-treat-custom)
1073 (defcustom gnus-treat-x-pgp-sig nil
1075 To automatically treat X-PGP-Sig, set it to head.
1076 Valid values are nil, t, `head', `last', an integer or a predicate.
1077 See the manual for details."
1078 :group 'gnus-article-treat
1079 :group 'mime-security
1080 :type gnus-article-treat-custom)
1082 (defvar gnus-article-encrypt-protocol-alist
1083 '(("PGP" . mml2015-self-encrypt)))
1085 ;; Set to nil if more than one protocol added to
1086 ;; gnus-article-encrypt-protocol-alist.
1087 (defcustom gnus-article-encrypt-protocol "PGP"
1088 "The protocol used for encrypt articles.
1089 It is a string, such as \"PGP\". If nil, ask user."
1091 :group 'mime-security)
1093 ;;; Internal variables
1095 (defvar gnus-english-month-names
1096 '("January" "February" "March" "April" "May" "June" "July" "August"
1097 "September" "October" "November" "December"))
1099 (defvar article-goto-body-goes-to-point-min-p nil)
1100 (defvar gnus-article-wash-types nil)
1101 (defvar gnus-article-emphasis-alist nil)
1103 (defvar gnus-article-mime-handle-alist-1 nil)
1104 (defvar gnus-treatment-function-alist
1105 '((gnus-treat-x-pgp-sig gnus-article-verify-x-pgp-sig)
1106 (gnus-treat-strip-banner gnus-article-strip-banner)
1107 (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
1108 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1109 (gnus-treat-buttonize gnus-article-add-buttons)
1110 (gnus-treat-fill-article gnus-article-fill-cited-article)
1111 (gnus-treat-fill-long-lines gnus-article-fill-long-lines)
1112 (gnus-treat-strip-cr gnus-article-remove-cr)
1113 (gnus-treat-emphasize gnus-article-emphasize)
1114 (gnus-treat-display-xface gnus-article-display-x-face)
1115 (gnus-treat-date-ut gnus-article-date-ut)
1116 (gnus-treat-date-local gnus-article-date-local)
1117 (gnus-treat-date-english gnus-article-date-english)
1118 (gnus-treat-date-lapsed gnus-article-date-lapsed)
1119 (gnus-treat-date-original gnus-article-date-original)
1120 (gnus-treat-date-user-defined gnus-article-date-user)
1121 (gnus-treat-date-iso8601 gnus-article-date-iso8601)
1122 (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
1123 (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
1124 (gnus-treat-hide-signature gnus-article-hide-signature)
1125 (gnus-treat-hide-citation gnus-article-hide-citation)
1126 (gnus-treat-hide-citation-maybe gnus-article-hide-citation-maybe)
1127 (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
1128 (gnus-treat-leading-whitespace gnus-article-remove-leading-whitespace)
1129 (gnus-treat-strip-pgp gnus-article-hide-pgp)
1130 (gnus-treat-strip-pem gnus-article-hide-pem)
1131 (gnus-treat-highlight-headers gnus-article-highlight-headers)
1132 (gnus-treat-highlight-citation gnus-article-highlight-citation)
1133 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1134 (gnus-treat-strip-trailing-blank-lines
1135 gnus-article-remove-trailing-blank-lines)
1136 (gnus-treat-strip-leading-blank-lines
1137 gnus-article-strip-leading-blank-lines)
1138 (gnus-treat-strip-multiple-blank-lines
1139 gnus-article-strip-multiple-blank-lines)
1140 (gnus-treat-overstrike gnus-article-treat-overstrike)
1141 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
1142 (gnus-treat-display-smileys gnus-smiley-display)
1143 (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
1144 (gnus-treat-display-picons gnus-article-display-picons)
1145 (gnus-treat-play-sounds gnus-earcon-display)))
1147 (defvar gnus-article-mime-handle-alist nil)
1148 (defvar article-lapsed-timer nil)
1149 (defvar gnus-article-current-summary nil)
1151 (defvar gnus-article-mode-syntax-table
1152 (let ((table (copy-syntax-table text-mode-syntax-table)))
1153 ;; This causes the citation match run O(2^n).
1154 ;; (modify-syntax-entry ?- "w" table)
1155 (modify-syntax-entry ?> ")" table)
1156 (modify-syntax-entry ?< "(" table)
1158 "Syntax table used in article mode buffers.
1159 Initialized from `text-mode-syntax-table.")
1161 (defvar gnus-save-article-buffer nil)
1163 (defvar gnus-article-mode-line-format-alist
1164 (nconc '((?w (gnus-article-wash-status) ?s)
1165 (?m (gnus-article-mime-part-status) ?s))
1166 gnus-summary-mode-line-format-alist))
1168 (defvar gnus-number-of-articles-to-be-saved nil)
1170 (defvar gnus-inhibit-hiding nil)
1172 (defsubst gnus-article-hide-text (b e props)
1173 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
1174 (gnus-add-text-properties-when 'article-type nil b e props)
1175 (when (memq 'intangible props)
1177 (max (1- b) (point-min))
1178 b 'intangible (cddr (memq 'intangible props)))))
1180 (defsubst gnus-article-unhide-text (b e)
1181 "Remove hidden text properties from region between B and E."
1182 (remove-text-properties b e gnus-hidden-properties)
1183 (when (memq 'intangible gnus-hidden-properties)
1184 (put-text-property (max (1- b) (point-min))
1185 b 'intangible nil)))
1187 (defun gnus-article-hide-text-type (b e type)
1188 "Hide text of TYPE between B and E."
1189 (push type gnus-article-wash-types)
1190 (gnus-article-hide-text
1191 b e (cons 'article-type (cons type gnus-hidden-properties))))
1193 (defun gnus-article-unhide-text-type (b e type)
1194 "Unhide text of TYPE between B and E."
1195 (setq gnus-article-wash-types
1196 (delq type gnus-article-wash-types))
1197 (remove-text-properties
1198 b e (cons 'article-type (cons type gnus-hidden-properties)))
1199 (when (memq 'intangible gnus-hidden-properties)
1200 (put-text-property (max (1- b) (point-min))
1201 b 'intangible nil)))
1203 (defun gnus-article-hide-text-of-type (type)
1204 "Hide text of TYPE in the current buffer."
1206 (let ((b (point-min))
1208 (while (setq b (text-property-any b e 'article-type type))
1209 (add-text-properties b (incf b) gnus-hidden-properties)))))
1211 (defun gnus-article-delete-text-of-type (type)
1212 "Delete text of TYPE in the current buffer."
1214 (let ((b (point-min)))
1215 (while (setq b (text-property-any b (point-max) 'article-type type))
1217 b (or (text-property-not-all b (point-max) 'article-type type)
1220 (defun gnus-article-delete-invisible-text ()
1221 "Delete all invisible text in the current buffer."
1223 (let ((b (point-min)))
1224 (while (setq b (text-property-any b (point-max) 'invisible t))
1226 b (or (text-property-not-all b (point-max) 'invisible t)
1229 (defun gnus-article-text-type-exists-p (type)
1230 "Say whether any text of type TYPE exists in the buffer."
1231 (text-property-any (point-min) (point-max) 'article-type type))
1233 (defsubst gnus-article-header-rank ()
1234 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1235 (let ((list gnus-sorted-header-list)
1238 (when (looking-at (car list))
1240 (setq list (cdr list))
1244 (defun article-hide-headers (&optional arg delete)
1245 "Hide unwanted headers and possibly sort them as well."
1247 ;; This function might be inhibited.
1248 (unless gnus-inhibit-hiding
1251 (let ((buffer-read-only nil)
1252 (case-fold-search t)
1253 (max (1+ (length gnus-sorted-header-list)))
1254 (ignored (when (not gnus-visible-headers)
1255 (cond ((stringp gnus-ignored-headers)
1256 gnus-ignored-headers)
1257 ((listp gnus-ignored-headers)
1258 (mapconcat 'identity gnus-ignored-headers
1261 (cond ((stringp gnus-visible-headers)
1262 gnus-visible-headers)
1263 ((and gnus-visible-headers
1264 (listp gnus-visible-headers))
1265 (mapconcat 'identity gnus-visible-headers "\\|"))))
1266 (inhibit-point-motion-hooks t)
1268 ;; First we narrow to just the headers.
1269 (article-narrow-to-head)
1270 ;; Hide any "From " lines at the beginning of (mail) articles.
1271 (while (looking-at "From ")
1274 (delete-region (point-min) (point)))
1275 ;; Then treat the rest of the header lines.
1276 ;; Then we use the two regular expressions
1277 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1278 ;; select which header lines is to remain visible in the
1280 (while (re-search-forward "^[^ \t:]*:" nil t)
1282 ;; Mark the rank of the header.
1284 (point) (1+ (point)) 'message-rank
1285 (if (or (and visible (looking-at visible))
1287 (not (looking-at ignored))))
1288 (gnus-article-header-rank)
1291 (message-sort-headers-1)
1292 (when (setq beg (text-property-any
1293 (point-min) (point-max) 'message-rank (+ 2 max)))
1294 ;; We delete the unwanted headers.
1295 (push 'headers gnus-article-wash-types)
1296 (add-text-properties (point-min) (+ 5 (point-min))
1297 '(article-type headers dummy-invisible t))
1298 (delete-region beg (point-max))))))))
1300 (defun article-hide-boring-headers (&optional arg)
1301 "Toggle hiding of headers that aren't very interesting.
1302 If given a negative prefix, always show; if given a positive prefix,
1304 (interactive (gnus-article-hidden-arg))
1305 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1306 (not gnus-show-all-headers))
1309 (let ((buffer-read-only nil)
1310 (list gnus-boring-article-headers)
1311 (inhibit-point-motion-hooks t)
1313 (article-narrow-to-head)
1315 (setq elem (pop list))
1316 (goto-char (point-min))
1318 ;; Hide empty headers.
1320 (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1322 (gnus-article-hide-text-type
1323 (progn (beginning-of-line) (point))
1326 (if (re-search-forward "^[^ \t]" nil t)
1330 ;; Hide boring Newsgroups header.
1331 ((eq elem 'newsgroups)
1332 (when (gnus-string-equal
1333 (gnus-fetch-field "newsgroups")
1334 (gnus-group-real-name
1335 (if (boundp 'gnus-newsgroup-name)
1338 (gnus-article-hide-header "newsgroups")))
1339 ((eq elem 'to-address)
1340 (let ((to (message-fetch-field "to"))
1342 (gnus-parameter-to-address
1343 (if (boundp 'gnus-newsgroup-name)
1344 gnus-newsgroup-name ""))))
1345 (when (and to to-address
1348 ;; only one address in To
1349 (nth 1 (mail-extract-address-components to))
1351 (gnus-article-hide-header "to"))))
1352 ((eq elem 'followup-to)
1353 (when (gnus-string-equal
1354 (message-fetch-field "followup-to")
1355 (message-fetch-field "newsgroups"))
1356 (gnus-article-hide-header "followup-to")))
1357 ((eq elem 'reply-to)
1358 (let ((from (message-fetch-field "from"))
1359 (reply-to (message-fetch-field "reply-to")))
1364 (nth 1 (mail-extract-address-components from))
1365 (nth 1 (mail-extract-address-components reply-to)))))
1366 (gnus-article-hide-header "reply-to"))))
1368 (let ((date (message-fetch-field "date")))
1370 (< (days-between (current-time-string) date)
1372 (gnus-article-hide-header "date"))))
1374 (let ((to (message-fetch-field "to"))
1375 (cc (message-fetch-field "cc")))
1376 (when (> (length to) 1024)
1377 (gnus-article-hide-header "to"))
1378 (when (> (length cc) 1024)
1379 (gnus-article-hide-header "cc"))))
1383 (goto-char (point-min))
1384 (while (re-search-forward "^to:" nil t)
1385 (setq to-count (1+ to-count)))
1386 (when (> to-count 1)
1387 (while (> to-count 0)
1388 (goto-char (point-min))
1390 (re-search-forward "^to:" nil nil to-count)
1392 (narrow-to-region (point) (point-max))
1393 (gnus-article-hide-header "to"))
1394 (setq to-count (1- to-count))))
1395 (goto-char (point-min))
1396 (while (re-search-forward "^cc:" nil t)
1397 (setq cc-count (1+ cc-count)))
1398 (when (> cc-count 1)
1399 (while (> cc-count 0)
1400 (goto-char (point-min))
1402 (re-search-forward "^cc:" nil nil cc-count)
1404 (narrow-to-region (point) (point-max))
1405 (gnus-article-hide-header "cc"))
1406 (setq cc-count (1- cc-count)))))))))))))
1408 (defun gnus-article-hide-header (header)
1410 (goto-char (point-min))
1411 (when (re-search-forward (concat "^" header ":") nil t)
1412 (gnus-article-hide-text-type
1413 (progn (beginning-of-line) (point))
1416 (if (re-search-forward "^[^ \t]" nil t)
1421 (defvar gnus-article-normalized-header-length 40
1422 "Length of normalized headers.")
1424 (defun article-normalize-headers ()
1425 "Make all header lines 40 characters long."
1427 (let ((buffer-read-only nil)
1431 (article-narrow-to-head)
1434 ((< (setq column (- (gnus-point-at-eol) (point)))
1435 gnus-article-normalized-header-length)
1437 (insert (make-string
1438 (- gnus-article-normalized-header-length column)
1440 ((> column gnus-article-normalized-header-length)
1441 (gnus-put-text-property
1443 (forward-char gnus-article-normalized-header-length)
1450 (forward-line 1))))))
1452 (defun article-treat-dumbquotes ()
1453 "Translate M****s*** sm*rtq**t*s into proper text.
1454 Note that this function guesses whether a character is a sm*rtq**t* or
1455 not, so it should only be used interactively.
1457 Sm*rtq**t*s are M****s***'s unilateral extension to the character map
1458 in an attempt to provide more quoting characters. If you see
1459 something like \\222 or \\264 where you're expecting some kind of
1460 apostrophe or quotation mark, then try this wash."
1462 (article-translate-strings gnus-article-dumbquotes-map))
1464 (defun article-translate-characters (from to)
1465 "Translate all characters in the body of the article according to FROM and TO.
1466 FROM is a string of characters to translate from; to is a string of
1467 characters to translate to."
1469 (when (article-goto-body)
1470 (let ((buffer-read-only nil)
1471 (x (make-string 225 ?x))
1473 (while (< (incf i) (length x))
1476 (while (< i (length from))
1477 (aset x (aref from i) (aref to i))
1479 (translate-region (point) (point-max) x)))))
1481 (defun article-translate-strings (map)
1482 "Translate all string in the body of the article according to MAP.
1483 MAP is an alist where the elements are on the form (\"from\" \"to\")."
1485 (when (article-goto-body)
1486 (let ((buffer-read-only nil)
1488 (while (setq elem (pop map))
1490 (while (search-forward (car elem) nil t)
1491 (replace-match (cadr elem)))))))))
1493 (defun article-treat-overstrike ()
1494 "Translate overstrikes into bold text."
1497 (when (article-goto-body)
1498 (let ((buffer-read-only nil))
1499 (while (search-forward "\b" nil t)
1500 (let ((next (char-after))
1501 (previous (char-after (- (point) 2))))
1502 ;; We do the boldification/underlining by hiding the
1503 ;; overstrikes and putting the proper text property
1507 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
1508 (put-text-property (point) (1+ (point)) 'face 'bold))
1510 (gnus-article-hide-text-type
1511 (1- (point)) (1+ (point)) 'overstrike)
1513 (- (point) 2) (1- (point)) 'face 'underline))
1515 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
1517 (point) (1+ (point)) 'face 'underline)))))))))
1519 (defun article-fill-long-lines ()
1520 "Fill lines that are wider than the window width."
1523 (let ((buffer-read-only nil)
1524 (width (window-width (get-buffer-window (current-buffer)))))
1527 (let ((adaptive-fill-mode nil)) ;Why? -sm
1530 (when (>= (current-column) (min fill-column width))
1531 (narrow-to-region (point) (gnus-point-at-bol))
1532 (fill-paragraph nil)
1533 (goto-char (point-max))
1535 (forward-line 1)))))))
1537 (defun article-capitalize-sentences ()
1538 "Capitalize the first word in each sentence."
1541 (let ((buffer-read-only nil)
1542 (paragraph-start "^[\n\^L]"))
1546 (forward-sentence)))))
1548 (defun article-remove-cr ()
1549 "Remove trailing CRs and then translate remaining CRs into LFs."
1552 (let ((buffer-read-only nil))
1553 (goto-char (point-min))
1554 (while (re-search-forward "\r+$" nil t)
1555 (replace-match "" t t))
1556 (goto-char (point-min))
1557 (while (search-forward "\r" nil t)
1558 (replace-match "\n" t t)))))
1560 (defun article-remove-trailing-blank-lines ()
1561 "Remove all trailing blank lines from the article."
1564 (let ((buffer-read-only nil))
1565 (goto-char (point-max))
1569 (while (and (not (bobp))
1570 (looking-at "^[ \t]*$")
1571 (not (gnus-annotation-in-region-p
1572 (point) (gnus-point-at-eol))))
1577 (defun article-display-x-face (&optional force)
1578 "Look for an X-Face header and display it if present."
1579 (interactive (list 'force))
1581 ;; Delete the old process, if any.
1582 (when (process-status "article-x-face")
1583 (delete-process "article-x-face"))
1584 (let ((inhibit-point-motion-hooks t)
1586 (case-fold-search t)
1589 (article-narrow-to-head)
1590 (when (and buffer-read-only ;; When type `W f'
1592 (goto-char (point-min))
1593 (not (re-search-forward "^X-Face:[\t ]*" nil t)))
1594 (gnus-buffer-live-p gnus-original-article-buffer))
1595 (with-current-buffer gnus-original-article-buffer
1597 (article-narrow-to-head)
1598 (while (re-search-forward "^X-Face:" nil t)
1604 (1- (re-search-forward
1605 "^\\($\\|[^ \t]\\)" nil t))))))))
1607 (let (point start bface eface buffer-read-only)
1608 (goto-char (point-max))
1610 (setq bface (get-text-property (gnus-point-at-bol) 'face)
1611 eface (get-text-property (1- (gnus-point-at-eol)) 'face))
1612 (goto-char (point-max))
1613 (setq point (point))
1616 (while (looking-at "\\([^:]+\\): *")
1617 (put-text-property (match-beginning 1) (1+ (match-end 1))
1619 (setq start (match-end 0))
1621 (while (looking-at "[\t ]")
1623 (put-text-property start (point)
1625 (goto-char (point-min))
1626 (setq from (message-fetch-field "from"))
1627 (goto-char (point-min))
1628 (while (and gnus-article-x-face-command
1631 ;; Check whether this face is censored.
1632 (not gnus-article-x-face-too-ugly)
1633 (and gnus-article-x-face-too-ugly from
1634 (not (string-match gnus-article-x-face-too-ugly
1636 ;; Has to be present.
1637 (re-search-forward "^X-Face:[\t ]*" nil t))
1638 ;; This used to try to do multiple faces (`while' instead of
1639 ;; `when' above), but (a) sending multiple EOFs to xv doesn't
1640 ;; work (b) it can crash some versions of Emacs (c) are
1641 ;; multiple faces really something to encourage?
1642 (when (stringp gnus-article-x-face-command)
1644 ;; We now have the area of the buffer where the X-Face is stored.
1647 (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t))))
1648 ;; We display the face.
1649 (if (symbolp gnus-article-x-face-command)
1650 ;; The command is a lisp function, so we call it.
1651 (if (gnus-functionp gnus-article-x-face-command)
1652 (funcall gnus-article-x-face-command beg end)
1653 (error "%s is not a function" gnus-article-x-face-command))
1654 ;; The command is a string, so we interpret the command
1655 ;; as a, well, command, and fork it off.
1656 (let ((process-connection-type nil))
1657 (process-kill-without-query
1659 "article-x-face" nil shell-file-name shell-command-switch
1660 gnus-article-x-face-command))
1661 (process-send-region "article-x-face" beg end)
1662 (process-send-eof "article-x-face"))))))))))
1664 (defun article-decode-mime-words ()
1665 "Decode all MIME-encoded words in the article."
1668 (set-buffer gnus-article-buffer)
1669 (let ((inhibit-point-motion-hooks t)
1671 (mail-parse-charset gnus-newsgroup-charset)
1672 (mail-parse-ignored-charsets
1673 (save-excursion (set-buffer gnus-summary-buffer)
1674 gnus-newsgroup-ignored-charsets)))
1675 (mail-decode-encoded-word-region (point-min) (point-max)))))
1677 (defun article-decode-charset (&optional prompt)
1678 "Decode charset-encoded text in the article.
1679 If PROMPT (the prefix), prompt for a coding system to use."
1681 (let ((inhibit-point-motion-hooks t) (case-fold-search t)
1683 (mail-parse-charset gnus-newsgroup-charset)
1684 (mail-parse-ignored-charsets
1685 (save-excursion (condition-case nil
1686 (set-buffer gnus-summary-buffer)
1688 gnus-newsgroup-ignored-charsets))
1689 ct cte ctl charset format)
1692 (article-narrow-to-head)
1693 (setq ct (message-fetch-field "Content-Type" t)
1694 cte (message-fetch-field "Content-Transfer-Encoding" t)
1695 ctl (and ct (ignore-errors
1696 (mail-header-parse-content-type ct)))
1699 (mm-read-coding-system "Charset to decode: "))
1701 (mail-content-type-get ctl 'charset)))
1702 format (and ctl (mail-content-type-get ctl 'format)))
1704 (setq cte (mail-header-strip cte)))
1705 (if (and ctl (not (string-match "/" (car ctl))))
1707 (goto-char (point-max)))
1710 (narrow-to-region (point) (point-max))
1711 (when (and (eq mail-parse-charset 'gnus-decoded)
1712 (eq (mm-body-7-or-8) '8bit))
1713 ;; The text code could have been decoded.
1714 (setq charset mail-parse-charset))
1715 (when (and (or (not ctl)
1716 (equal (car ctl) "text/plain"))
1717 (not format)) ;; article with format will decode later.
1719 charset (and cte (intern (downcase
1720 (gnus-strip-whitespace cte))))
1723 (defun article-decode-encoded-words ()
1724 "Remove encoded-word encoding from headers."
1725 (let ((inhibit-point-motion-hooks t)
1726 (mail-parse-charset gnus-newsgroup-charset)
1727 (mail-parse-ignored-charsets
1728 (save-excursion (condition-case nil
1729 (set-buffer gnus-summary-buffer)
1731 gnus-newsgroup-ignored-charsets))
1734 (article-narrow-to-head)
1735 (funcall gnus-decode-header-function (point-min) (point-max)))))
1737 (defun article-de-quoted-unreadable (&optional force read-charset)
1738 "Translate a quoted-printable-encoded article.
1739 If FORCE, decode the article whether it is marked as quoted-printable
1741 If READ-CHARSET, ask for a coding system."
1742 (interactive (list 'force current-prefix-arg))
1744 (let ((buffer-read-only nil) type charset)
1745 (if (gnus-buffer-live-p gnus-original-article-buffer)
1746 (with-current-buffer gnus-original-article-buffer
1748 (gnus-fetch-field "content-transfer-encoding"))
1749 (let* ((ct (gnus-fetch-field "content-type"))
1752 (mail-header-parse-content-type ct)))))
1753 (setq charset (and ctl
1754 (mail-content-type-get ctl 'charset)))
1755 (if (stringp charset)
1756 (setq charset (intern (downcase charset)))))))
1758 (setq charset (mm-read-coding-system "Charset: " charset)))
1760 (setq charset gnus-newsgroup-charset))
1762 (and type (let ((case-fold-search t))
1763 (string-match "quoted-printable" type))))
1765 (quoted-printable-decode-region
1766 (point) (point-max) (mm-charset-to-coding-system charset))))))
1768 (defun article-de-base64-unreadable (&optional force read-charset)
1769 "Translate a base64 article.
1770 If FORCE, decode the article whether it is marked as base64 not.
1771 If READ-CHARSET, ask for a coding system."
1772 (interactive (list 'force current-prefix-arg))
1774 (let ((buffer-read-only nil) type charset)
1775 (if (gnus-buffer-live-p gnus-original-article-buffer)
1776 (with-current-buffer gnus-original-article-buffer
1778 (gnus-fetch-field "content-transfer-encoding"))
1779 (let* ((ct (gnus-fetch-field "content-type"))
1782 (mail-header-parse-content-type ct)))))
1783 (setq charset (and ctl
1784 (mail-content-type-get ctl 'charset)))
1785 (if (stringp charset)
1786 (setq charset (intern (downcase charset)))))))
1788 (setq charset (mm-read-coding-system "Charset: " charset)))
1790 (setq charset gnus-newsgroup-charset))
1792 (and type (let ((case-fold-search t))
1793 (string-match "base64" type))))
1796 (narrow-to-region (point) (point-max))
1797 (base64-decode-region (point-min) (point-max))
1798 (mm-decode-coding-region
1799 (point-min) (point-max) (mm-charset-to-coding-system charset)))))))
1804 (defun article-decode-HZ ()
1805 "Translate a HZ-encoded article."
1809 (let ((buffer-read-only nil))
1810 (rfc1843-decode-region (point-min) (point-max)))))
1812 (defun article-wash-html (&optional read-charset)
1813 "Format an html article.
1814 If READ-CHARSET, ask for a coding system."
1817 (let ((buffer-read-only nil)
1819 (if (gnus-buffer-live-p gnus-original-article-buffer)
1820 (with-current-buffer gnus-original-article-buffer
1821 (let* ((ct (gnus-fetch-field "content-type"))
1824 (mail-header-parse-content-type ct)))))
1825 (setq charset (and ctl
1826 (mail-content-type-get ctl 'charset)))
1827 (if (stringp charset)
1828 (setq charset (intern (downcase charset)))))))
1830 (setq charset (mm-read-coding-system "Charset: " charset)))
1832 (setq charset gnus-newsgroup-charset))
1834 (save-window-excursion
1836 (narrow-to-region (point) (point-max))
1838 (let ((w3-strict-width (window-width))
1839 (url-standalone-mode t))
1841 (w3-region (point-min) (point-max))
1844 (defun article-hide-list-identifiers ()
1845 "Remove list identifies from the Subject header.
1846 The `gnus-list-identifiers' variable specifies what to do."
1848 (let ((inhibit-point-motion-hooks t)
1849 (regexp (if (consp gnus-list-identifiers)
1850 (mapconcat 'identity gnus-list-identifiers " *\\|")
1851 gnus-list-identifiers))
1856 (article-narrow-to-head)
1857 (goto-char (point-min))
1858 (while (re-search-forward
1859 (concat "^Subject: +\\(R[Ee]: +\\)*\\(" regexp " *\\)")
1861 (delete-region (match-beginning 2) (match-end 0))
1862 (beginning-of-line))
1863 (when (re-search-forward
1864 "^Subject: +\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" nil t)
1865 (delete-region (match-beginning 1) (match-end 1))))))))
1867 (defun article-hide-pgp ()
1868 "Remove any PGP headers and signatures in the current article."
1872 (let ((inhibit-point-motion-hooks t)
1873 buffer-read-only beg end)
1875 ;; Hide the "header".
1876 (when (re-search-forward "^-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
1877 (push 'pgp gnus-article-wash-types)
1878 (delete-region (match-beginning 0) (match-end 0))
1879 ;; Remove armor headers (rfc2440 6.2)
1880 (delete-region (point) (or (re-search-forward "^[ \t]*\n" nil t)
1883 ;; Hide the actual signature.
1884 (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
1885 (setq end (1+ (match-beginning 0)))
1888 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
1890 ;; Perhaps we shouldn't hide to the end of the buffer
1891 ;; if there is no end to the signature?
1893 ;; Hide "- " PGP quotation markers.
1895 (narrow-to-region beg end)
1896 (goto-char (point-min))
1897 (while (re-search-forward "^- " nil t)
1899 (match-beginning 0) (match-end 0)))
1901 (gnus-run-hooks 'gnus-article-hide-pgp-hook))))))
1903 (defun article-hide-pem (&optional arg)
1904 "Toggle hiding of any PEM headers and signatures in the current article.
1905 If given a negative prefix, always show; if given a positive prefix,
1907 (interactive (gnus-article-hidden-arg))
1908 (unless (gnus-article-check-hidden-text 'pem arg)
1910 (let (buffer-read-only end)
1911 (goto-char (point-min))
1912 ;; Hide the horrendously ugly "header".
1913 (when (and (search-forward
1914 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
1916 (setq end (1+ (match-beginning 0))))
1917 (push 'pem gnus-article-wash-types)
1918 (gnus-article-hide-text-type
1920 (if (search-forward "\n\n" nil t)
1924 ;; Hide the trailer as well
1925 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
1927 (gnus-article-hide-text-type
1928 (match-beginning 0) (match-end 0) 'pem)))))))
1930 (defun article-strip-banner ()
1931 "Strip the banner specified by the `banner' group parameter."
1935 (let ((inhibit-point-motion-hooks t)
1936 (banner (gnus-parameter-banner gnus-newsgroup-name))
1937 (gnus-signature-limit nil)
1938 buffer-read-only beg end)
1942 ((eq banner 'signature)
1943 (when (gnus-article-narrow-to-signature)
1946 (delete-region (point) (point-max))))
1948 (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
1949 (while (re-search-forward banner nil t)
1950 (delete-region (match-beginning 0) (match-end 0)))))
1952 (while (re-search-forward banner nil t)
1953 (delete-region (match-beginning 0) (match-end 0))))))))))
1955 (defun article-babel ()
1956 "Translate article using an online translation service."
1960 (set-buffer gnus-article-buffer)
1961 (when (article-goto-body)
1962 (let* ((buffer-read-only nil)
1965 (orig (buffer-substring start end))
1966 (trans (babel-as-string orig)))
1968 (narrow-to-region start end)
1969 (delete-region start end)
1972 (defun article-hide-signature (&optional arg)
1973 "Hide the signature in the current article.
1974 If given a negative prefix, always show; if given a positive prefix,
1976 (interactive (gnus-article-hidden-arg))
1977 (unless (gnus-article-check-hidden-text 'signature arg)
1980 (let ((buffer-read-only nil))
1981 (when (gnus-article-narrow-to-signature)
1982 (gnus-article-hide-text-type
1983 (point-min) (point-max) 'signature)))))))
1985 (defun article-strip-headers-in-body ()
1986 "Strip offensive headers from bodies."
1990 (let ((case-fold-search t))
1991 (when (looking-at "x-no-archive:")
1992 (gnus-delete-line)))))
1994 (defun article-strip-leading-blank-lines ()
1995 "Remove all blank lines from the beginning of the article."
1998 (let ((inhibit-point-motion-hooks t)
2000 (when (article-goto-body)
2001 (while (and (not (eobp))
2002 (looking-at "[ \t]*$"))
2003 (gnus-delete-line))))))
2005 (defun article-narrow-to-head ()
2006 "Narrow the buffer to the head of the message.
2007 Point is left at the beginning of the narrowed-to region."
2009 (goto-char (point-min))
2010 (if (search-forward "\n\n" nil 1)
2013 (goto-char (point-min)))
2015 (defun article-goto-body ()
2016 "Place point at the start of the body."
2017 (goto-char (point-min))
2019 ;; This variable is only bound when dealing with separate
2021 (article-goto-body-goes-to-point-min-p
2023 ((search-forward "\n\n" nil t)
2026 (goto-char (point-max))
2029 (defun article-strip-multiple-blank-lines ()
2030 "Replace consecutive blank lines with one empty line."
2033 (let ((inhibit-point-motion-hooks t)
2035 ;; First make all blank lines empty.
2037 (while (re-search-forward "^[ \t]+$" nil t)
2038 (unless (gnus-annotation-in-region-p
2039 (match-beginning 0) (match-end 0))
2040 (replace-match "" nil t)))
2041 ;; Then replace multiple empty lines with a single empty line.
2043 (while (re-search-forward "\n\n\\(\n+\\)" nil t)
2044 (unless (gnus-annotation-in-region-p
2045 (match-beginning 0) (match-end 0))
2046 (delete-region (match-beginning 1) (match-end 1)))))))
2048 (defun article-strip-leading-space ()
2049 "Remove all white space from the beginning of the lines in the article."
2052 (let ((inhibit-point-motion-hooks t)
2055 (while (re-search-forward "^[ \t]+" nil t)
2056 (replace-match "" t t)))))
2058 (defun article-strip-trailing-space ()
2059 "Remove all white space from the end of the lines in the article."
2062 (let ((inhibit-point-motion-hooks t)
2065 (while (re-search-forward "[ \t]+$" nil t)
2066 (replace-match "" t t)))))
2068 (defun article-strip-blank-lines ()
2069 "Strip leading, trailing and multiple blank lines."
2071 (article-strip-leading-blank-lines)
2072 (article-remove-trailing-blank-lines)
2073 (article-strip-multiple-blank-lines))
2075 (defun article-strip-all-blank-lines ()
2076 "Strip all blank lines."
2079 (let ((inhibit-point-motion-hooks t)
2082 (while (re-search-forward "^[ \t]*\n" nil t)
2083 (replace-match "" t t)))))
2085 (defun gnus-article-narrow-to-signature ()
2086 "Narrow to the signature; return t if a signature is found, else nil."
2087 (let ((inhibit-point-motion-hooks t))
2088 (when (gnus-article-search-signature)
2090 ;; Check whether we have some limits to what we consider
2091 ;; to be a signature.
2092 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
2093 (list gnus-signature-limit)))
2095 (while (setq limit (pop limits))
2096 (if (or (and (integerp limit)
2097 (< (- (point-max) (point)) limit))
2099 (< (count-lines (point) (point-max)) limit))
2100 (and (gnus-functionp limit)
2102 (and (stringp limit)
2103 (not (re-search-forward limit nil t))))
2104 () ; This limit did not succeed.
2108 (narrow-to-region (point) (point-max))
2111 (defun gnus-article-search-signature ()
2112 "Search the current buffer for the signature separator.
2113 Put point at the beginning of the signature separator."
2114 (let ((cur (point)))
2115 (goto-char (point-max))
2116 (if (if (stringp gnus-signature-separator)
2117 (re-search-backward gnus-signature-separator nil t)
2118 (let ((seps gnus-signature-separator))
2120 (not (re-search-backward (car seps) nil t)))
2127 (defun gnus-article-hidden-arg ()
2128 "Return the current prefix arg as a number, or 0 if no prefix."
2129 (list (if current-prefix-arg
2130 (prefix-numeric-value current-prefix-arg)
2133 (defun gnus-article-check-hidden-text (type arg)
2134 "Return nil if hiding is necessary.
2135 Arg can be nil or a number. Nil and positive means hide, negative
2136 means show, 0 means toggle."
2139 (let ((hide (gnus-article-hidden-text-p type)))
2145 (gnus-article-show-hidden-text type)
2148 (if (eq hide 'hidden)
2150 (gnus-article-show-hidden-text type)
2154 (defun gnus-article-hidden-text-p (type)
2155 "Say whether the current buffer contains hidden text of type TYPE."
2156 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
2158 (not (get-text-property pos 'invisible))
2159 (not (get-text-property pos 'dummy-invisible)))
2161 (text-property-any (1+ pos) (point-max) 'article-type type)))
2166 (defun gnus-article-show-hidden-text (type &optional dummy)
2167 "Show all hidden text of type TYPE.
2168 Originally it is hide instead of DUMMY."
2169 (let ((buffer-read-only nil)
2170 (inhibit-point-motion-hooks t))
2171 (gnus-remove-text-properties-when
2173 (point-min) (point-max)
2174 (cons 'article-type (cons type
2175 gnus-hidden-properties)))))
2177 (defconst article-time-units
2178 `((year . ,(* 365.25 24 60 60))
2179 (week . ,(* 7 24 60 60))
2180 (day . ,(* 24 60 60))
2184 "Mapping from time units to seconds.")
2186 (defun article-date-ut (&optional type highlight header)
2187 "Convert DATE date to universal time in the current article.
2188 If TYPE is `local', convert to local time; if it is `lapsed', output
2189 how much time has lapsed since DATE. For `lapsed', the value of
2190 `gnus-article-date-lapsed-new-header' says whether the \"X-Sent:\" header
2191 should replace the \"Date:\" one, or should be added below it."
2192 (interactive (list 'ut t))
2193 (let* ((header (or header
2194 (message-fetch-field "date")
2196 (tdate-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
2199 ((not gnus-article-date-lapsed-new-header)
2205 (date (if (vectorp header) (mail-header-date header)
2207 (inhibit-point-motion-hooks t)
2212 (article-narrow-to-head)
2213 (when (re-search-forward tdate-regexp nil t)
2214 (setq bface (get-text-property (gnus-point-at-bol) 'face)
2215 date (or (get-text-property (gnus-point-at-bol)
2218 eface (get-text-property (1- (gnus-point-at-eol)) 'face))
2220 (when (and date (not (string= date "")))
2221 (goto-char (point-min))
2222 (let ((buffer-read-only nil))
2223 ;; Delete any old Date headers.
2224 (while (re-search-forward date-regexp nil t)
2226 (delete-region (progn (beginning-of-line) (point))
2227 (progn (forward-line 1) (point)))
2228 (delete-region (progn (beginning-of-line) (point))
2229 (progn (end-of-line) (point)))
2230 (setq pos (point))))
2231 (when (and (not pos) (re-search-forward tdate-regexp nil t))
2233 (if pos (goto-char pos))
2234 (insert (article-make-date-line date (or type 'ut)))
2240 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
2241 (put-text-property (match-beginning 1) (1+ (match-end 1))
2242 'original-date date)
2243 (put-text-property (match-beginning 1) (1+ (match-end 1))
2245 (put-text-property (match-beginning 2) (match-end 2)
2248 (defun article-make-date-line (date type)
2249 "Return a DATE line of TYPE."
2250 (unless (memq type '(local ut original user iso8601 lapsed english))
2251 (error "Unknown conversion type: %s" type))
2253 (let ((time (date-to-time date)))
2255 ;; Convert to the local timezone.
2257 (let ((tz (car (current-time-zone time))))
2258 (format "Date: %s %s%02d%02d" (current-time-string time)
2259 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2260 (/ (% (abs tz) 3600) 60))))
2261 ;; Convert to Universal Time.
2264 (current-time-string
2265 (let* ((e (parse-time-string date))
2266 (tm (apply 'encode-time e))
2268 (ls (- (cadr tm) (car (current-time-zone time)))))
2269 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
2270 ((> ls 65535) (list (1+ ms) (- ls 65536)))
2273 ;; Get the original date from the article.
2274 ((eq type 'original)
2275 (concat "Date: " (if (string-match "\n+$" date)
2276 (substring date 0 (match-beginning 0))
2278 ;; Let the user define the format.
2280 (if (gnus-functionp gnus-article-time-format)
2281 (funcall gnus-article-time-format time)
2284 (format-time-string gnus-article-time-format time))))
2287 (let ((tz (car (current-time-zone time))))
2290 (format-time-string "%Y%m%dT%H%M%S" time)
2291 (format "%s%02d%02d"
2292 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2293 (/ (% (abs tz) 3600) 60)))))
2294 ;; Do an X-Sent lapsed format.
2296 ;; If the date is seriously mangled, the timezone functions are
2297 ;; liable to bug out, so we ignore all errors.
2298 (let* ((now (current-time))
2299 (real-time (subtract-time now time))
2300 (real-sec (and real-time
2301 (+ (* (float (car real-time)) 65536)
2303 (sec (and real-time (abs real-sec)))
2313 ;; This is a bit convoluted, but basically we go
2314 ;; through the time units for years, weeks, etc,
2315 ;; and divide things to see whether that results
2316 ;; in positive answers.
2319 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
2320 ;; The (remaining) seconds are too few to
2321 ;; be divided into this time unit.
2323 ;; It's big enough, so we output it.
2324 (setq sec (- sec (* num (cdr unit))))
2326 (concat (if prev ", " "") (int-to-string
2328 " " (symbol-name (car unit))
2329 (if (> num 1) "s" ""))
2331 article-time-units "")
2332 ;; If dates are odd, then it might appear like the
2333 ;; article was sent in the future.
2336 " in the future"))))))
2337 ;; Display the date in proper English
2339 (let ((dtime (decode-time time)))
2342 (number-to-string (nth 3 dtime))
2343 (let ((digit (% (nth 3 dtime) 10)))
2345 ((memq (nth 3 dtime) '(11 12 13)) "th")
2351 (nth (1- (nth 4 dtime)) gnus-english-month-names)
2353 (number-to-string (nth 5 dtime))
2355 (format "%02d" (nth 2 dtime))
2357 (format "%02d" (nth 1 dtime)))))))
2359 (format "Date: %s (from Oort)" date))))
2361 (defun article-date-local (&optional highlight)
2362 "Convert the current article date to the local timezone."
2363 (interactive (list t))
2364 (article-date-ut 'local highlight))
2366 (defun article-date-english (&optional highlight)
2367 "Convert the current article date to something that is proper English."
2368 (interactive (list t))
2369 (article-date-ut 'english highlight))
2371 (defun article-date-original (&optional highlight)
2372 "Convert the current article date to what it was originally.
2373 This is only useful if you have used some other date conversion
2374 function and want to see what the date was before converting."
2375 (interactive (list t))
2376 (article-date-ut 'original highlight))
2378 (defun article-date-lapsed (&optional highlight)
2379 "Convert the current article date to time lapsed since it was sent."
2380 (interactive (list t))
2381 (article-date-ut 'lapsed highlight))
2383 (defun article-update-date-lapsed ()
2384 "Function to be run from a timer to update the lapsed time line."
2385 (let (deactivate-mark)
2390 (set-buffer (window-buffer w))
2391 (when (eq major-mode 'gnus-article-mode)
2392 (goto-char (point-min))
2393 (when (re-search-forward "^X-Sent:" nil t)
2394 (article-date-lapsed t))))
2397 (defun gnus-start-date-timer (&optional n)
2398 "Start a timer to update the X-Sent header in the article buffers.
2399 The numerical prefix says how frequently (in seconds) the function
2404 (gnus-stop-date-timer)
2405 (setq article-lapsed-timer
2406 (nnheader-run-at-time 1 n 'article-update-date-lapsed)))
2408 (defun gnus-stop-date-timer ()
2409 "Stop the X-Sent timer."
2411 (when article-lapsed-timer
2412 (nnheader-cancel-timer article-lapsed-timer)
2413 (setq article-lapsed-timer nil)))
2415 (defun article-date-user (&optional highlight)
2416 "Convert the current article date to the user-defined format.
2417 This format is defined by the `gnus-article-time-format' variable."
2418 (interactive (list t))
2419 (article-date-ut 'user highlight))
2421 (defun article-date-iso8601 (&optional highlight)
2422 "Convert the current article date to ISO8601."
2423 (interactive (list t))
2424 (article-date-ut 'iso8601 highlight))
2426 (defun article-show-all ()
2427 "Show all hidden text in the article buffer."
2430 (let ((buffer-read-only nil))
2431 (gnus-article-unhide-text (point-min) (point-max)))))
2433 (defun article-remove-leading-whitespace ()
2434 "Remove excessive whitespace from all headers."
2438 (let ((buffer-read-only nil))
2439 (article-narrow-to-head)
2440 (goto-char (point-min))
2441 (while (re-search-forward "^[^ :]+: \\([ \t]+\\)" nil t)
2442 (delete-region (match-beginning 1) (match-end 1)))))))
2444 (defun article-emphasize (&optional arg)
2445 "Emphasize text according to `gnus-emphasis-alist'."
2446 (interactive (gnus-article-hidden-arg))
2447 (unless (gnus-article-check-hidden-text 'emphasis arg)
2451 (with-current-buffer gnus-summary-buffer
2452 gnus-article-emphasis-alist)
2454 gnus-emphasis-alist))
2455 (buffer-read-only nil)
2456 (props (append '(article-type emphasis)
2457 gnus-hidden-properties))
2458 regexp elem beg invisible visible face)
2461 (while (setq elem (pop alist))
2463 (setq regexp (car elem)
2464 invisible (nth 1 elem)
2465 visible (nth 2 elem)
2467 (while (re-search-forward regexp nil t)
2468 (when (and (match-beginning visible) (match-beginning invisible))
2469 (push 'emphasis gnus-article-wash-types)
2470 (gnus-article-hide-text
2471 (match-beginning invisible) (match-end invisible) props)
2472 (gnus-article-unhide-text-type
2473 (match-beginning visible) (match-end visible) 'emphasis)
2474 (gnus-put-text-property-excluding-newlines
2475 (match-beginning visible) (match-end visible) 'face face)
2476 (goto-char (match-end invisible)))))))))
2478 (defun gnus-article-setup-highlight-words (&optional highlight-words)
2479 "Setup newsgroup emphasis alist."
2480 (unless gnus-article-emphasis-alist
2481 (let ((name (and gnus-newsgroup-name
2482 (gnus-group-real-name gnus-newsgroup-name))))
2483 (make-local-variable 'gnus-article-emphasis-alist)
2484 (setq gnus-article-emphasis-alist
2486 (let ((alist gnus-group-highlight-words-alist) elem highlight)
2487 (while (setq elem (pop alist))
2488 (when (and name (string-match (car elem) name))
2490 highlight (copy-sequence (cdr elem)))))
2492 (copy-sequence highlight-words)
2493 (if gnus-newsgroup-name
2494 (copy-sequence (gnus-group-find-parameter
2495 gnus-newsgroup-name 'highlight-words t)))
2496 gnus-emphasis-alist)))))
2499 (defvar gnus-summary-article-menu)
2500 (defvar gnus-summary-post-menu))
2502 ;;; Saving functions.
2504 (defun gnus-article-save (save-buffer file &optional num)
2505 "Save the currently selected article."
2506 (unless gnus-save-all-headers
2507 ;; Remove headers according to `gnus-saved-headers'.
2508 (let ((gnus-visible-headers
2509 (or gnus-saved-headers gnus-visible-headers))
2510 (gnus-article-buffer save-buffer))
2512 (set-buffer save-buffer)
2513 (article-hide-headers 1 t))))
2514 (save-window-excursion
2515 (if (not gnus-default-article-saver)
2516 (error "No default saver is defined")
2517 ;; !!! Magic! The saving functions all save
2518 ;; `gnus-save-article-buffer' (or so they think), but we
2519 ;; bind that variable to our save-buffer.
2520 (set-buffer gnus-article-buffer)
2521 (let* ((gnus-save-article-buffer save-buffer)
2524 ((not gnus-prompt-before-saving) 'default)
2525 ((eq gnus-prompt-before-saving 'always) nil)
2527 (gnus-number-of-articles-to-be-saved
2528 (when (eq gnus-prompt-before-saving t)
2530 (set-buffer gnus-article-current-summary)
2531 (funcall gnus-default-article-saver filename)))))
2533 (defun gnus-read-save-file-name (prompt &optional filename
2534 function group headers variable)
2536 (funcall function group headers (symbol-value variable)))
2541 ((eq filename 'default)
2547 (let* ((split-name (gnus-get-split-value gnus-split-methods))
2550 (if (and gnus-number-of-articles-to-be-saved
2551 (> gnus-number-of-articles-to-be-saved 1))
2552 (format "these %d articles"
2553 gnus-number-of-articles-to-be-saved)
2556 ;; Let the split methods have their say.
2558 ;; No split name was found.
2561 (concat prompt " (default "
2562 (file-name-nondirectory default-name) ") ")
2563 (file-name-directory default-name)
2565 ;; A single group name is returned.
2566 ((stringp split-name)
2568 (funcall function split-name headers
2569 (symbol-value variable)))
2571 (concat prompt " (default "
2572 (file-name-nondirectory default-name) ") ")
2573 (file-name-directory default-name)
2575 ;; A single split name was found
2576 ((= 1 (length split-name))
2577 (let* ((name (expand-file-name
2579 gnus-article-save-directory))
2580 (dir (cond ((file-directory-p name)
2581 (file-name-as-directory name))
2582 ((file-exists-p name) name)
2583 (t gnus-article-save-directory))))
2585 (concat prompt " (default " name ") ")
2587 ;; A list of splits was found.
2589 (setq split-name (nreverse split-name))
2591 (let ((file-name-history
2592 (nconc split-name file-name-history)))
2596 (concat prompt " (`M-p' for defaults) ")
2597 gnus-article-save-directory
2599 gnus-article-save-directory)))
2600 (car (push result file-name-history)))))))
2601 ;; Create the directory.
2602 (gnus-make-directory (file-name-directory file))
2603 ;; If we have read a directory, we append the default file name.
2604 (when (file-directory-p file)
2605 (setq file (expand-file-name (file-name-nondirectory
2607 (file-name-as-directory file))))
2608 ;; Possibly translate some characters.
2609 (nnheader-translate-file-chars file))))))
2610 (gnus-make-directory (file-name-directory result))
2611 (set variable result)))
2613 (defun gnus-article-archive-name (group)
2614 "Return the first instance of an \"Archive-name\" in the current buffer."
2615 (let ((case-fold-search t))
2616 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
2617 (nnheader-concat gnus-article-save-directory
2618 (match-string 1)))))
2620 (defun gnus-article-nndoc-name (group)
2621 "If GROUP is an nndoc group, return the name of the parent group."
2622 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
2623 (gnus-group-get-parameter group 'save-article-group)))
2625 (defun gnus-summary-save-in-rmail (&optional filename)
2626 "Append this article to Rmail file.
2627 Optional argument FILENAME specifies file name.
2628 Directory to save to is default to `gnus-article-save-directory'."
2629 (setq filename (gnus-read-save-file-name
2630 "Save %s in rmail file:" filename
2631 gnus-rmail-save-name gnus-newsgroup-name
2632 gnus-current-headers 'gnus-newsgroup-last-rmail))
2633 (gnus-eval-in-buffer-window gnus-save-article-buffer
2637 (gnus-output-to-rmail filename))))
2640 (defun gnus-summary-save-in-mail (&optional filename)
2641 "Append this article to Unix mail file.
2642 Optional argument FILENAME specifies file name.
2643 Directory to save to is default to `gnus-article-save-directory'."
2644 (setq filename (gnus-read-save-file-name
2645 "Save %s in Unix mail file:" filename
2646 gnus-mail-save-name gnus-newsgroup-name
2647 gnus-current-headers 'gnus-newsgroup-last-mail))
2648 (gnus-eval-in-buffer-window gnus-save-article-buffer
2652 (if (and (file-readable-p filename)
2653 (mail-file-babyl-p filename))
2654 (rmail-output-to-rmail-file filename t)
2655 (gnus-output-to-mail filename)))))
2658 (defun gnus-summary-save-in-file (&optional filename overwrite)
2659 "Append this article to file.
2660 Optional argument FILENAME specifies file name.
2661 Directory to save to is default to `gnus-article-save-directory'."
2662 (setq filename (gnus-read-save-file-name
2663 "Save %s in file:" filename
2664 gnus-file-save-name gnus-newsgroup-name
2665 gnus-current-headers 'gnus-newsgroup-last-file))
2666 (gnus-eval-in-buffer-window gnus-save-article-buffer
2670 (when (and overwrite
2671 (file-exists-p filename))
2672 (delete-file filename))
2673 (gnus-output-to-file filename))))
2676 (defun gnus-summary-write-to-file (&optional filename)
2677 "Write this article to a file.
2678 Optional argument FILENAME specifies file name.
2679 The directory to save in defaults to `gnus-article-save-directory'."
2680 (gnus-summary-save-in-file nil t))
2682 (defun gnus-summary-save-body-in-file (&optional filename)
2683 "Append this article body to a file.
2684 Optional argument FILENAME specifies file name.
2685 The directory to save in defaults to `gnus-article-save-directory'."
2686 (setq filename (gnus-read-save-file-name
2687 "Save %s body in file:" filename
2688 gnus-file-save-name gnus-newsgroup-name
2689 gnus-current-headers 'gnus-newsgroup-last-file))
2690 (gnus-eval-in-buffer-window gnus-save-article-buffer
2694 (when (article-goto-body)
2695 (narrow-to-region (point) (point-max)))
2696 (gnus-output-to-file filename))))
2699 (defun gnus-summary-save-in-pipe (&optional command)
2700 "Pipe this article to subprocess."
2702 (cond ((and (eq command 'default)
2703 gnus-last-shell-command)
2704 gnus-last-shell-command)
2709 "Shell command on %s: "
2710 (if (and gnus-number-of-articles-to-be-saved
2711 (> gnus-number-of-articles-to-be-saved 1))
2712 (format "these %d articles"
2713 gnus-number-of-articles-to-be-saved)
2715 gnus-last-shell-command))))
2716 (when (string-equal command "")
2717 (if gnus-last-shell-command
2718 (setq command gnus-last-shell-command)
2719 (error "A command is required")))
2720 (gnus-eval-in-buffer-window gnus-article-buffer
2723 (shell-command-on-region (point-min) (point-max) command nil)))
2724 (setq gnus-last-shell-command command))
2726 ;;; Article file names when saving.
2728 (defun gnus-capitalize-newsgroup (newsgroup)
2729 "Capitalize NEWSGROUP name."
2730 (when (not (zerop (length newsgroup)))
2731 (concat (char-to-string (upcase (aref newsgroup 0)))
2732 (substring newsgroup 1))))
2734 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
2735 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2736 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
2737 Otherwise, it is like ~/News/news/group/num."
2740 (concat (if (gnus-use-long-file-name 'not-save)
2741 (gnus-capitalize-newsgroup newsgroup)
2742 (gnus-newsgroup-directory-form newsgroup))
2743 "/" (int-to-string (mail-header-number headers)))
2744 gnus-article-save-directory)))
2746 (string-equal (file-name-directory default)
2747 (file-name-directory last-file))
2748 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2750 (or last-file default))))
2752 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
2753 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2754 If variable `gnus-use-long-file-name' is non-nil, it is
2755 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
2758 (concat (if (gnus-use-long-file-name 'not-save)
2760 (gnus-newsgroup-directory-form newsgroup))
2761 "/" (int-to-string (mail-header-number headers)))
2762 gnus-article-save-directory)))
2764 (string-equal (file-name-directory default)
2765 (file-name-directory last-file))
2766 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2768 (or last-file default))))
2770 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
2771 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2772 If variable `gnus-use-long-file-name' is non-nil, it is
2773 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
2776 (if (gnus-use-long-file-name 'not-save)
2779 (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup))
2781 gnus-article-save-directory)))
2783 (defun gnus-sender-save-name (newsgroup headers &optional last-file)
2784 "Generate file name from sender."
2785 (let ((from (mail-header-from headers)))
2787 (if (and from (string-match "\\([^ <]+\\)@" from))
2788 (match-string 1 from)
2790 gnus-article-save-directory)))
2792 (defun article-verify-x-pgp-sig ()
2795 (if (gnus-buffer-live-p gnus-original-article-buffer)
2796 (let ((sig (with-current-buffer gnus-original-article-buffer
2797 (gnus-fetch-field "X-PGP-Sig")))
2801 (mml2015-clear-verify-function))
2803 (insert-buffer gnus-original-article-buffer)
2804 (setq items (split-string sig))
2805 (message-narrow-to-head)