1 ;;; article.el --- article treatment functions
2 ;; Copyright (C) 1996 Free Software Foundation, Inc.
4 ;; Author: Lars Magne Ingebrigtsen <larsi@ifi.uio.no>
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
37 (defcustom gnus-ignored-headers
38 '("^Path:" "^Posting-Version:" "^Article-I.D.:" "^Expires:"
39 "^Date-Received:" "^References:" "^Control:" "^Xref:" "^Lines:"
40 "^Posted:" "^Relay-Version:" "^Message-ID:" "^Nf-ID:" "^Nf-From:"
41 "^Approved:" "^Sender:" "^Received:" "^Mail-from:")
42 "All headers that match this regexp will be hidden.
43 This variable can also be a list of regexps of headers to be ignored.
44 If `article-visible-headers' is non-nil, this variable will be ignored."
45 :type '(repeat string) ;Leave monster regexp to lisp.
48 (defcustom gnus-visible-headers
49 '("^From:" "^Newsgroups:" "^Subject:" "^Date:" "^Followup-To:"
50 "^Reply-To:" "^Organization:" "^Summary:" "^Keywords:" "^To:"
51 "^Cc:" "^Posted-To:" "^Mail-Copies-To:" "^Apparently-To:"
52 "^Gnus-Warning:" "^Resent-")
53 "All headers that do not match this regexp will be hidden.
54 This variable can also be a list of regexp of headers to remain visible.
55 If this variable is non-nil, `gnus-article-ignored-headers' will be ignored."
56 :type '(repeat string) ;Leave monster regexp to lisp.
59 (defcustom gnus-sorted-header-list
60 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:" "^To:"
61 "^Cc:" "^Date:" "^Organization:")
62 "This variable is a list of regular expressions.
63 If it is non-nil, headers that match the regular expressions will
64 be placed first in the article buffer in the sequence specified by
66 :type '(repeat string)
69 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
70 "Headers that are only to be displayed if they have interesting data.
71 Possible values in this list are `empty', `newsgroups', `followup-to',
72 `reply-to', and `date'."
73 :type '(set (item :tag "Headers with no content." empty)
74 (item :tag "Newsgroups with only one group." newsgroups)
75 (item :tag "Followup-to identical to newsgroups." followup-to)
76 (item :tag "Reply-to identical to from." reply-to)
77 (item :tag "Date less than four days old." date))
80 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
81 "Regexp matching signature separator.
82 This can also be a list of regexps. In that case, it will be checked
83 from head to tail looking for a separator. Searches will be done from
84 the end of the buffer."
85 :type '(repeat string)
88 (defcustom gnus-signature-limit nil
89 "Provide a limit to what is considered a signature.
90 If it is a number, no signature may not be longer (in characters) than
91 that number. If it is a floating point number, no signature may be
92 longer (in lines) than that number. If it is a function, the function
93 will be called without any parameters, and if it returns nil, there is
94 no signature in the buffer. If it is a string, it will be used as a
95 regexp. If it matches, the text in question is not a signature."
96 :type '(choice integer number function string)
99 (defcustom gnus-hidden-properties '(invisible t intangible t)
100 "Property list to use for hiding text."
104 (defcustom gnus-article-x-face-command
105 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | xv -quit -"
106 "String or function to be executed to display an X-Face header.
107 If it is a string, the command will be executed in a sub-shell
108 asynchronously. The compressed face will be piped to this command."
109 :type 'string ;Leave function case to Lisp.
112 (defcustom gnus-article-x-face-too-ugly nil
113 "Regexp matching posters whose face shouldn't be shown automatically."
117 (defcustom gnus-emphasis-alist
118 '(("_\\(\\w+\\)_" 0 1 underline)
119 ("\\W\\(/\\(\\w+\\)/\\)\\W" 1 2 italic)
120 ("\\(_\\*\\|\\*_\\)\\(\\w+\\)\\(_\\*\\|\\*_\\)" 0 2 bold-underline)
121 ("\\*\\(\\w+\\)\\*" 0 1 bold))
122 "Alist that says how to fontify certain phrases.
123 Each item looks like this:
125 (\"_\\\\([[\\w+\\\\)_\" 0 1 'underline)
127 The first element is a regular expression to be matched. The second
128 is a number that says what regular expression grouping used to find
129 the entire emphasized word. The third is a number that says what
130 regexp grouping should be displayed and highlighted. The fourth
131 is the face used for highlighting."
132 :type '(repeat (list :value ("" 0 0 default)
134 (integer :tag "Match group")
135 (integer :tag "Emphasize group")
140 (autoload 'hexl-hex-string-to-integer "hexl")
141 (autoload 'timezone-make-date-arpa-standard "timezone")
142 (autoload 'mail-extract-address-components "mail-extr"))
144 ;;; Internal variables.
146 (defvar gnus-inhibit-hiding nil)
147 (defvar gnus-newsgroup-name)
149 (defsubst article-hide-text (b e props)
150 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
151 (add-text-properties b e props)
152 (when (memq 'intangible props)
154 (max (1- b) (point-min))
155 b 'intangible (cddr (memq 'intangible props)))))
157 (defsubst article-unhide-text (b e)
158 "Remove hidden text properties from region between B and E."
159 (remove-text-properties b e gnus-hidden-properties)
160 (when (memq 'intangible gnus-hidden-properties)
161 (put-text-property (max (1- b) (point-min))
164 (defun article-hide-text-type (b e type)
165 "Hide text of TYPE between B and E."
167 b e (cons 'article-type (cons type gnus-hidden-properties))))
169 (defun article-unhide-text-type (b e type)
170 "Hide text of TYPE between B and E."
171 (remove-text-properties
172 b e (cons 'article-type (cons type gnus-hidden-properties)))
173 (when (memq 'intangible gnus-hidden-properties)
174 (put-text-property (max (1- b) (point-min))
177 (defun article-hide-text-of-type (type)
178 "Hide text of TYPE in the current buffer."
180 (let ((b (point-min))
182 (while (setq b (text-property-any b e 'article-type type))
183 (add-text-properties b (incf b) gnus-hidden-properties)))))
185 (defun article-delete-text-of-type (type)
186 "Delete text of TYPE in the current buffer."
188 (let ((b (point-min))
190 (while (setq b (text-property-any b e 'article-type type))
191 (delete-region b (incf b))))))
193 (defun article-text-type-exists-p (type)
194 "Say whether any text of type TYPE exists in the buffer."
195 (text-property-any (point-min) (point-max) 'article-type type))
197 (defsubst article-header-rank ()
198 "Give the rank of the string HEADER as given by `article-sorted-header-list'."
199 (let ((list gnus-sorted-header-list)
202 (when (looking-at (car list))
204 (setq list (cdr list))
208 (defun article-hide-headers (&optional arg delete)
209 "Toggle whether to hide unwanted headers and possibly sort them as well.
210 If given a negative prefix, always show; if given a positive prefix,
212 (interactive (article-hidden-arg))
213 (if (article-check-hidden-text 'headers arg)
214 ;; Show boring headers as well.
215 (article-show-hidden-text 'boring-headers)
216 ;; This function might be inhibited.
217 (unless gnus-inhibit-hiding
220 (let ((buffer-read-only nil)
221 (props (nconc (list 'article-type 'headers)
222 gnus-hidden-properties))
223 (max (1+ (length gnus-sorted-header-list)))
224 (ignored (when (not gnus-visible-headers)
225 (cond ((stringp gnus-ignored-headers)
226 gnus-ignored-headers)
227 ((listp gnus-ignored-headers)
228 (mapconcat 'identity gnus-ignored-headers
231 (cond ((stringp gnus-visible-headers)
232 gnus-visible-headers)
233 ((and gnus-visible-headers
234 (listp gnus-visible-headers))
235 (mapconcat 'identity gnus-visible-headers "\\|"))))
236 (inhibit-point-motion-hooks t)
238 ;; First we narrow to just the headers.
240 (goto-char (point-min))
241 ;; Hide any "From " lines at the beginning of (mail) articles.
242 (while (looking-at "From ")
246 (delete-region (point-min) (point))
247 (article-hide-text (point-min) (point) props)))
248 ;; Then treat the rest of the header lines.
251 (progn (search-forward "\n\n" nil t) (forward-line -1) (point)))
252 ;; Then we use the two regular expressions
253 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
254 ;; select which header lines is to remain visible in the
256 (goto-char (point-min))
257 (while (re-search-forward "^[^ \t]*:" nil t)
259 ;; Mark the rank of the header.
261 (point) (1+ (point)) 'message-rank
262 (if (or (and visible (looking-at visible))
264 (not (looking-at ignored))))
265 (article-header-rank)
268 (message-sort-headers-1)
269 (when (setq beg (text-property-any
270 (point-min) (point-max) 'message-rank (+ 2 max)))
271 ;; We make the unwanted headers invisible.
273 (delete-region beg (point-max))
274 ;; Suggested by Sudish Joseph <joseph@cis.ohio-state.edu>.
275 (article-hide-text-type beg (point-max) 'headers))
276 ;; Work around XEmacs lossage.
277 (put-text-property (point-min) beg 'invisible nil))))))))
279 (defun article-hide-boring-headers (&optional arg)
280 "Toggle hiding of headers that aren't very interesting.
281 If given a negative prefix, always show; if given a positive prefix,
283 (interactive (article-hidden-arg))
284 (unless (article-check-hidden-text 'boring-headers arg)
287 (let ((buffer-read-only nil)
288 (list gnus-boring-article-headers)
289 (inhibit-point-motion-hooks t)
291 (nnheader-narrow-to-headers)
293 (setq elem (pop list))
294 (goto-char (point-min))
296 ;; Hide empty headers.
298 (while (re-search-forward "^[^:]+:[ \t]*\n[^ \t]" nil t)
300 (article-hide-text-type
301 (progn (beginning-of-line) (point))
304 (if (re-search-forward "^[^ \t]" nil t)
308 ;; Hide boring Newsgroups header.
309 ((eq elem 'newsgroups)
310 (when (equal (gnus-fetch-field "newsgroups")
311 (gnus-group-real-name
312 (if (boundp 'gnus-newsgroup-name)
315 (article-hide-header "newsgroups")))
316 ((eq elem 'followup-to)
317 (when (equal (message-fetch-field "followup-to")
318 (message-fetch-field "newsgroups"))
319 (article-hide-header "followup-to")))
321 (let ((from (message-fetch-field "from"))
322 (reply-to (message-fetch-field "reply-to")))
326 (nth 1 (mail-extract-address-components from))
327 (nth 1 (mail-extract-address-components reply-to))))
328 (article-hide-header "reply-to"))))
330 (let ((date (message-fetch-field "date")))
332 (< (gnus-days-between date (current-time-string))
334 (article-hide-header "date")))))))))))
336 (defun article-hide-header (header)
338 (goto-char (point-min))
339 (when (re-search-forward (concat "^" header ":") nil t)
340 (article-hide-text-type
341 (progn (beginning-of-line) (point))
344 (if (re-search-forward "^[^ \t]" nil t)
349 ;; Written by Per Abrahamsen <amanda@iesd.auc.dk>.
350 (defun article-treat-overstrike ()
351 "Translate overstrikes into bold text."
354 (let ((buffer-read-only nil))
355 (while (search-forward "\b" nil t)
356 (let ((next (following-char))
357 (previous (char-after (- (point) 2))))
358 ;; We do the boldification/underlining by hiding the
359 ;; overstrikes and putting the proper text property
363 (article-hide-text-type (- (point) 2) (point) 'overstrike)
364 (put-text-property (point) (1+ (point)) 'face 'bold))
366 (article-hide-text-type (1- (point)) (1+ (point)) 'overstrike)
368 (- (point) 2) (1- (point)) 'face 'underline))
370 (article-hide-text-type (- (point) 2) (point) 'overstrike)
372 (point) (1+ (point)) 'face 'underline))))))))
374 (defun article-fill ()
375 "Format too long lines."
378 (let ((buffer-read-only nil))
380 (goto-char (point-min))
381 (search-forward "\n\n" nil t)
383 (let ((paragraph-start "^[>|#:<;* ]*[ \t]*$")
384 (adaptive-fill-regexp "[ \t]*\\([|#:<;>*]+ *\\)?")
385 (adaptive-fill-mode t))
387 (and (>= (current-column) (min fill-column (window-width)))
388 (/= (preceding-char) ?:)
389 (fill-paragraph nil))
392 (defun article-remove-cr ()
393 "Remove carriage returns from an article."
396 (let ((buffer-read-only nil))
397 (goto-char (point-min))
398 (while (search-forward "\r" nil t)
399 (replace-match "" t t)))))
401 (defun article-remove-trailing-blank-lines ()
402 "Remove all trailing blank lines from the article."
405 (let ((buffer-read-only nil))
406 (goto-char (point-max))
410 (while (looking-at "^[ \t]*$")
415 (defun article-display-x-face (&optional force)
416 "Look for an X-Face header and display it if present."
417 (interactive (list 'force))
419 ;; Delete the old process, if any.
420 (when (process-status "article-x-face")
421 (delete-process "article-x-face"))
422 (let ((inhibit-point-motion-hooks t)
423 (case-fold-search nil)
426 (nnheader-narrow-to-headers)
427 (setq from (message-fetch-field "from"))
428 (goto-char (point-min))
429 (when (and gnus-article-x-face-command
431 ;; Check whether this face is censored.
432 (not gnus-article-x-face-too-ugly)
433 (and gnus-article-x-face-too-ugly from
434 (not (string-match gnus-article-x-face-too-ugly
436 ;; Has to be present.
437 (re-search-forward "^X-Face: " nil t))
438 ;; We now have the area of the buffer where the X-Face is stored.
440 (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t))))
441 ;; We display the face.
442 (if (symbolp gnus-article-x-face-command)
443 ;; The command is a lisp function, so we call it.
444 (if (gnus-functionp gnus-article-x-face-command)
445 (funcall gnus-article-x-face-command beg end)
446 (error "%s is not a function" gnus-article-x-face-command))
447 ;; The command is a string, so we interpret the command
448 ;; as a, well, command, and fork it off.
449 (let ((process-connection-type nil))
450 (process-kill-without-query
452 "article-x-face" nil shell-file-name shell-command-switch
453 gnus-article-x-face-command))
454 (process-send-region "article-x-face" beg end)
455 (process-send-eof "article-x-face")))))))))
457 (defun article-decode-rfc1522 ()
458 "Hack to remove QP encoding from headers."
459 (let ((case-fold-search t)
460 (inhibit-point-motion-hooks t)
461 (buffer-read-only nil)
465 (goto-char (point-min))
466 (or (search-forward "\n\n" nil t) (point-max)))
467 (goto-char (point-min))
468 (while (re-search-forward
469 "=\\?iso-8859-1\\?q\\?\\([^?\t\n]*\\)\\?=" nil t)
470 (setq string (match-string 1))
472 (narrow-to-region (match-beginning 0) (match-end 0))
473 (delete-region (point-min) (point-max))
475 (article-mime-decode-quoted-printable (goto-char (point-min))
477 (subst-char-in-region (point-min) (point-max) ?_ ? )
478 (goto-char (point-max)))
479 (if (looking-at "\\([ \t\n]+\\)=\\?")
480 (replace-match "" t t nil 1))
481 (goto-char (point-min))))))
483 (defun article-de-quoted-unreadable (&optional force)
484 "Do a naive translation of a quoted-printable-encoded article.
485 This is in no way, shape or form meant as a replacement for real MIME
486 processing, but is simply a stop-gap measure until MIME support is
488 If FORCE, decode the article whether it is marked as quoted-printable
490 (interactive (list 'force))
492 (let ((case-fold-search t)
493 (buffer-read-only nil)
494 (type (gnus-fetch-field "content-transfer-encoding")))
495 (article-decode-rfc1522)
497 (and type (string-match "quoted-printable" (downcase type))))
498 (goto-char (point-min))
499 (search-forward "\n\n" nil 'move)
500 (article-mime-decode-quoted-printable (point) (point-max))))))
502 (defun article-mime-decode-quoted-printable-buffer ()
503 "Decode Quoted-Printable in the current buffer."
504 (article-mime-decode-quoted-printable (point-min) (point-max)))
506 (defun article-mime-decode-quoted-printable (from to)
507 "Decode Quoted-Printable in the region between FROM and TO."
510 (while (search-forward "=" to t)
511 (cond ((eq (following-char) ?\n)
514 ((looking-at "[0-9A-F][0-9A-F]")
515 (subst-char-in-region
516 (1- (point)) (point) ?=
517 (hexl-hex-string-to-integer
518 (buffer-substring (point) (+ 2 (point)))))
522 ((gnus-message 3 "Malformed MIME quoted-printable message")))))
524 (defun article-hide-pgp (&optional arg)
525 "Toggle hiding of any PGP headers and signatures in the current article.
526 If given a negative prefix, always show; if given a positive prefix,
528 (interactive (article-hidden-arg))
529 (unless (article-check-hidden-text 'pgp arg)
531 (let (buffer-read-only beg end)
533 (goto-char (point-min))
534 ;; Hide the "header".
535 (and (search-forward "\n-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
536 (article-hide-text-type (match-beginning 0) (match-end 0) 'pgp))
538 ;; Hide the actual signature.
539 (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
540 (setq end (1+ (match-beginning 0)))
541 (article-hide-text-type
543 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
545 ;; Perhaps we shouldn't hide to the end of the buffer
546 ;; if there is no end to the signature?
549 ;; Hide "- " PGP quotation markers.
551 (narrow-to-region beg end)
552 (goto-char (point-min))
553 (while (re-search-forward "^- " nil t)
554 (article-hide-text-type (match-beginning 0) (match-end 0) 'pgp))
557 (defun article-hide-pem (&optional arg)
558 "Toggle hiding of any PEM headers and signatures in the current article.
559 If given a negative prefix, always show; if given a positive prefix,
561 (interactive (article-hidden-arg))
562 (unless (article-check-hidden-text 'pem arg)
564 (let (buffer-read-only end)
566 (goto-char (point-min))
567 ;; hide the horrendously ugly "header".
568 (and (search-forward "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
571 (setq end (1+ (match-beginning 0)))
572 (article-hide-text-type
574 (if (search-forward "\n\n" nil t)
578 ;; hide the trailer as well
579 (and (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
582 (article-hide-text-type
583 (match-beginning 0) (match-end 0) 'pem))))))
585 (defun article-hide-signature (&optional arg)
586 "Hide the signature in the current article.
587 If given a negative prefix, always show; if given a positive prefix,
589 (interactive (article-hidden-arg))
590 (unless (article-check-hidden-text 'signature arg)
593 (let ((buffer-read-only nil))
594 (when (article-narrow-to-signature)
595 (article-hide-text-type (point-min) (point-max) 'signature)))))))
597 (defun article-strip-leading-blank-lines ()
598 "Remove all blank lines from the beginning of the article."
601 (let (buffer-read-only)
602 (goto-char (point-min))
603 (when (search-forward "\n\n" nil t)
604 (while (looking-at "[ \t]$")
605 (gnus-delete-line))))))
607 (defun article-strip-multiple-blank-lines ()
608 "Replace consecutive blank lines with one empty line."
611 (let (buffer-read-only)
612 ;; First make all blank lines empty.
613 (goto-char (point-min))
614 (while (re-search-forward "^[ \t]+$" nil t)
615 (replace-match "" nil t))
616 ;; Then replace multiple empty lines with a single empty line.
617 (goto-char (point-min))
618 (while (re-search-forward "\n\n\n+" nil t)
619 (replace-match "\n\n" t t)))))
621 (defun article-strip-blank-lines ()
622 "Strip leading, trailing and multiple blank lines."
624 (article-strip-leading-blank-lines)
625 (article-remove-trailing-blank-lines)
626 (article-strip-multiple-blank-lines))
628 (defvar mime::preview/content-list)
629 (defvar mime::preview-content-info/point-min)
630 (defun article-narrow-to-signature ()
631 "Narrow to the signature."
633 (when (and (boundp 'mime::preview/content-list)
634 mime::preview/content-list)
635 ;; We have a MIMEish article, so we use the MIME data to narrow.
636 (let ((pcinfo (car (last mime::preview/content-list))))
639 (funcall (intern "mime::preview-content-info/point-min") pcinfo)
643 (when (article-search-signature)
645 ;; Check whether we have some limits to what we consider
646 ;; to be a signature.
647 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
648 (list gnus-signature-limit)))
650 (while (setq limit (pop limits))
651 (if (or (and (integerp limit)
652 (< (- (point-max) (point)) limit))
654 (< (count-lines (point) (point-max)) limit))
655 (and (gnus-functionp limit)
658 (not (re-search-forward limit nil t))))
659 () ; This limit did not succeed.
663 (narrow-to-region (point) (point-max))
666 (defun article-search-signature ()
667 "Search the current buffer for the signature separator.
668 Put point at the beginning of the signature separator."
670 (goto-char (point-max))
671 (if (if (stringp gnus-signature-separator)
672 (re-search-backward gnus-signature-separator nil t)
673 (let ((seps gnus-signature-separator))
675 (not (re-search-backward (car seps) nil t)))
682 (defun article-hidden-arg ()
683 "Return the current prefix arg as a number, or 0 if no prefix."
684 (list (if current-prefix-arg
685 (prefix-numeric-value current-prefix-arg)
688 (defun article-check-hidden-text (type arg)
689 "Return nil if hiding is necessary.
690 Arg can be nil or a number. Nil and positive means hide, negative
691 means show, 0 means toggle."
693 (let ((hide (article-hidden-text-p type)))
699 (article-show-hidden-text type))
701 (if (eq hide 'hidden)
702 (article-show-hidden-text type)
705 (defun article-hidden-text-p (type)
706 "Say whether the current buffer contains hidden text of type TYPE."
707 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
709 (if (get-text-property pos 'invisible)
713 (defun article-show-hidden-text (type &optional hide)
714 "Show all hidden text of type TYPE.
715 If HIDE, hide the text instead."
717 (let ((buffer-read-only nil)
718 (inhibit-point-motion-hooks t)
720 (while (gnus-goto-char (text-property-any
721 beg (point-max) 'article-type type))
725 (article-hide-text beg (point) gnus-hidden-properties)
726 (article-unhide-text beg (point)))
730 (defconst article-time-units
731 `((year . ,(* 365.25 24 60 60))
732 (week . ,(* 7 24 60 60))
733 (day . ,(* 24 60 60))
737 "Mapping from time units to seconds.")
739 (defun article-date-ut (&optional type highlight header)
740 "Convert DATE date to universal time in the current article.
741 If TYPE is `local', convert to local time; if it is `lapsed', output
742 how much time has lapsed since DATE."
743 (interactive (list 'ut t))
744 (let* ((header (or header (message-fetch-field "date") ""))
745 (date (if (vectorp header) (mail-header-date header)
747 (date-regexp "^Date: \\|^X-Sent: ")
748 (inhibit-point-motion-hooks t)
750 (when (and date (not (string= date "")))
753 (nnheader-narrow-to-headers)
754 (let ((buffer-read-only nil))
755 ;; Delete any old Date headers.
756 (if (re-search-forward date-regexp nil t)
758 (setq bface (get-text-property (gnus-point-at-bol) 'face)
759 eface (get-text-property (1- (gnus-point-at-eol))
761 (message-remove-header date-regexp t)
763 (goto-char (point-max)))
764 (insert (article-make-date-line date type))
767 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
768 (put-text-property (match-beginning 1) (match-end 1)
770 (put-text-property (match-beginning 2) (match-end 2)
773 (defun article-make-date-line (date type)
774 "Return a DATE line of TYPE."
776 ;; Convert to the local timezone. We have to slap a
777 ;; `condition-case' round the calls to the timezone
778 ;; functions since they aren't particularly resistant to
781 (concat "Date: " (condition-case ()
782 (timezone-make-date-arpa-standard date)
785 ;; Convert to Universal Time.
789 (timezone-make-date-arpa-standard date nil "UT")
792 ;; Get the original date from the article.
794 (concat "Date: " date "\n"))
795 ;; Do an X-Sent lapsed format.
797 ;; If the date is seriously mangled, the timezone
798 ;; functions are liable to bug out, so we condition-case
800 (let* ((now (current-time))
805 (timezone-make-date-arpa-standard
806 (current-time-string now)
807 (current-time-zone now) "UT"))
809 (timezone-make-date-arpa-standard
812 (real-sec (and real-time
813 (+ (* (float (car real-time)) 65536)
815 (sec (and real-time (abs real-sec)))
825 ;; This is a bit convoluted, but basically we go
826 ;; through the time units for years, weeks, etc,
827 ;; and divide things to see whether that results
828 ;; in positive answers.
831 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
832 ;; The (remaining) seconds are too few to
833 ;; be divided into this time unit.
835 ;; It's big enough, so we output it.
836 (setq sec (- sec (* num (cdr unit))))
838 (concat (if prev ", " "") (int-to-string
840 " " (symbol-name (car unit))
841 (if (> num 1) "s" ""))
843 article-time-units "")
844 ;; If dates are odd, then it might appear like the
845 ;; article was sent in the future.
848 " in the future\n"))))))
850 (error "Unknown conversion type: %s" type))))
852 (defun article-date-local (&optional highlight)
853 "Convert the current article date to the local timezone."
854 (interactive (list t))
855 (article-date-ut 'local highlight))
857 (defun article-date-original (&optional highlight)
858 "Convert the current article date to what it was originally.
859 This is only useful if you have used some other date conversion
860 function and want to see what the date was before converting."
861 (interactive (list t))
862 (article-date-ut 'original highlight))
864 (defun article-date-lapsed (&optional highlight)
865 "Convert the current article date to time lapsed since it was sent."
866 (interactive (list t))
867 (article-date-ut 'lapsed highlight))
869 (defun article-show-all ()
870 "Show all hidden text in the article buffer."
873 (let ((buffer-read-only nil))
874 (article-unhide-text (point-min) (point-max)))))
876 (defun article-emphasize (&optional arg)
877 "Emphasize text according to `gnus-emphasis-alist'."
878 (interactive (article-hidden-arg))
879 (unless (article-check-hidden-text 'emphasis arg)
881 (let ((alist gnus-emphasis-alist)
882 (buffer-read-only nil)
883 (props (append '(article-type emphasis)
884 gnus-hidden-properties))
885 regexp elem beg invisible visible face)
886 (goto-char (point-min))
887 (search-forward "\n\n" nil t)
889 (while (setq elem (pop alist))
891 (setq regexp (car elem)
892 invisible (nth 1 elem)
895 (while (re-search-forward regexp nil t)
897 (match-beginning invisible) (match-end invisible) props)
898 (article-unhide-text-type
899 (match-beginning visible) (match-end visible) 'emphasis)
901 (match-beginning visible) (match-end visible)
906 ;;; article.el ends here