annotate lisp/mail/rmailsort.el @ 2851:3b0a06fc7c4b

(rmail-sortable-date-string): Handle date in format produced by current-time-string.
author Richard M. Stallman <rms@gnu.org>
date Mon, 17 May 1993 22:18:34 +0000
parents f680a6fb6661
children 2c1553d7aad1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
658
7cbd4fcd8b0f *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 584
diff changeset
1 ;;; rmailsort.el --- Rmail: sort messages.
7cbd4fcd8b0f *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 584
diff changeset
2
845
213978acbc1e entered into RCS
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 814
diff changeset
3 ;; Copyright (C) 1990 Free Software Foundation, Inc.
213978acbc1e entered into RCS
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 814
diff changeset
4
814
38b2499cb3e9 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 807
diff changeset
5 ;; Keywords: mail
807
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 767
diff changeset
6
767
02bfc9709961 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 658
diff changeset
7 ;; This file is part of GNU Emacs.
90
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
8
767
02bfc9709961 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 658
diff changeset
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
02bfc9709961 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 658
diff changeset
10 ;; it under the terms of the GNU General Public License as published by
807
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 767
diff changeset
11 ;; the Free Software Foundation; either version 2, or (at your option)
767
02bfc9709961 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 658
diff changeset
12 ;; any later version.
90
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
13
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
14 ;; GNU Emacs is distributed in the hope that it will be useful,
767
02bfc9709961 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 658
diff changeset
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
02bfc9709961 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 658
diff changeset
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
02bfc9709961 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 658
diff changeset
17 ;; GNU General Public License for more details.
90
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
18
767
02bfc9709961 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 658
diff changeset
19 ;; You should have received a copy of the GNU General Public License
02bfc9709961 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 658
diff changeset
20 ;; along with GNU Emacs; see the file COPYING. If not, write to
02bfc9709961 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 658
diff changeset
21 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
02bfc9709961 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 658
diff changeset
22
807
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 767
diff changeset
23 ;;; Code:
90
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
24
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
25 (require 'rmail)
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
26 (require 'sort)
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
27
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
28 ;; GNUS compatible key bindings.
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
29 (define-key rmail-mode-map "\C-c\C-s\C-d" 'rmail-sort-by-date)
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
30 (define-key rmail-mode-map "\C-c\C-s\C-s" 'rmail-sort-by-subject)
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
31 (define-key rmail-mode-map "\C-c\C-s\C-a" 'rmail-sort-by-author)
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
32 (define-key rmail-mode-map "\C-c\C-s\C-r" 'rmail-sort-by-recipient)
131
d4c523560fe8 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 92
diff changeset
33 (define-key rmail-mode-map "\C-c\C-s\C-c" 'rmail-sort-by-correspondent)
148
a099f0c77321 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 131
diff changeset
34 (define-key rmail-mode-map "\C-c\C-s\C-l" 'rmail-sort-by-size-lines)
90
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
35
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
36 (defun rmail-sort-by-date (reverse)
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
37 "Sort messages of current Rmail file by date.
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
38 If prefix argument REVERSE is non-nil, sort them in reverse order."
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
39 (interactive "P")
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
40 (rmail-sort-messages reverse
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
41 (function
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
42 (lambda (msg)
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
43 (rmail-sortable-date-string
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
44 (rmail-fetch-field msg "Date"))))))
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
45
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
46 (defun rmail-sort-by-subject (reverse)
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
47 "Sort messages of current Rmail file by subject.
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
48 If prefix argument REVERSE is non-nil, sort them in reverse order."
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
49 (interactive "P")
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
50 (rmail-sort-messages reverse
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
51 (function
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
52 (lambda (msg)
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
53 (let ((key (or (rmail-fetch-field msg "Subject") ""))
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
54 (case-fold-search t))
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
55 ;; Remove `Re:'
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
56 (if (string-match "^\\(re:[ \t]+\\)*" key)
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
57 (substring key (match-end 0)) key))))))
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
58
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
59 (defun rmail-sort-by-author (reverse)
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
60 "Sort messages of current Rmail file by author.
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
61 If prefix argument REVERSE is non-nil, sort them in reverse order."
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
62 (interactive "P")
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
63 (rmail-sort-messages reverse
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
64 (function
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
65 (lambda (msg)
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
66 (mail-strip-quoted-names
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
67 (or (rmail-fetch-field msg "From")
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
68 (rmail-fetch-field msg "Sender") ""))))))
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
69
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
70 (defun rmail-sort-by-recipient (reverse)
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
71 "Sort messages of current Rmail file by recipient.
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
72 If prefix argument REVERSE is non-nil, sort them in reverse order."
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
73 (interactive "P")
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
74 (rmail-sort-messages reverse
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
75 (function
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
76 (lambda (msg)
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
77 (mail-strip-quoted-names
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
78 (or (rmail-fetch-field msg "To")
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
79 (rmail-fetch-field msg "Apparently-To") "")
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
80 )))))
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
81
131
d4c523560fe8 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 92
diff changeset
82 (defun rmail-sort-by-correspondent (reverse)
d4c523560fe8 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 92
diff changeset
83 "Sort messages of current Rmail file by other correspondent.
d4c523560fe8 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 92
diff changeset
84 If prefix argument REVERSE is non-nil, sort them in reverse order."
d4c523560fe8 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 92
diff changeset
85 (interactive "P")
d4c523560fe8 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 92
diff changeset
86 (rmail-sort-messages reverse
d4c523560fe8 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 92
diff changeset
87 (function
d4c523560fe8 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 92
diff changeset
88 (lambda (msg)
d4c523560fe8 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 92
diff changeset
89 (rmail-select-correspondent
d4c523560fe8 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 92
diff changeset
90 msg
d4c523560fe8 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 92
diff changeset
91 '("From" "Sender" "To" "Apparently-To"))))))
d4c523560fe8 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 92
diff changeset
92
d4c523560fe8 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 92
diff changeset
93 (defun rmail-select-correspondent (msg fields)
d4c523560fe8 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 92
diff changeset
94 (let ((ans ""))
d4c523560fe8 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 92
diff changeset
95 (while (and fields (string= ans ""))
d4c523560fe8 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 92
diff changeset
96 (setq ans
d4c523560fe8 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 92
diff changeset
97 (rmail-dont-reply-to
d4c523560fe8 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 92
diff changeset
98 (mail-strip-quoted-names
d4c523560fe8 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 92
diff changeset
99 (or (rmail-fetch-field msg (car fields)) ""))))
d4c523560fe8 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 92
diff changeset
100 (setq fields (cdr fields)))
d4c523560fe8 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 92
diff changeset
101 ans))
148
a099f0c77321 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 131
diff changeset
102
a099f0c77321 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 131
diff changeset
103 (defun rmail-sort-by-size-lines (reverse)
a099f0c77321 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 131
diff changeset
104 "Sort messages of current Rmail file by message size.
a099f0c77321 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 131
diff changeset
105 If prefix argument REVERSE is non-nil, sort them in reverse order."
a099f0c77321 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 131
diff changeset
106 (interactive "P")
a099f0c77321 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 131
diff changeset
107 (rmail-sort-messages reverse
a099f0c77321 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 131
diff changeset
108 (function
a099f0c77321 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 131
diff changeset
109 (lambda (msg)
a099f0c77321 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 131
diff changeset
110 (format "%9d"
a099f0c77321 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 131
diff changeset
111 (count-lines (rmail-msgbeg msgnum)
a099f0c77321 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 131
diff changeset
112 (rmail-msgend msgnum)))))))
90
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
113
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
114
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
115 (defun rmail-sort-messages (reverse keyfunc)
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
116 "Sort messages of current Rmail file.
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
117 1st argument REVERSE is non-nil, sort them in reverse order.
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
118 2nd argument KEYFUNC is called with message number, and should return a key."
1430
f680a6fb6661 (rmail-sort-messages): Give up right away if not Rmail mode.
Richard M. Stallman <rms@gnu.org>
parents: 845
diff changeset
119 (or (eq major-mode 'rmail-mode)
f680a6fb6661 (rmail-sort-messages): Give up right away if not Rmail mode.
Richard M. Stallman <rms@gnu.org>
parents: 845
diff changeset
120 (error "Current buffer not in Rmail mode"))
90
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
121 (let ((buffer-read-only nil)
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
122 (sort-lists nil))
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
123 (message "Finding sort keys...")
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
124 (widen)
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
125 (let ((msgnum 1))
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
126 (while (>= rmail-total-messages msgnum)
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
127 (setq sort-lists
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
128 (cons (cons (funcall keyfunc msgnum) ;A sort key.
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
129 (buffer-substring
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
130 (rmail-msgbeg msgnum) (rmail-msgend msgnum)))
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
131 sort-lists))
148
a099f0c77321 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 131
diff changeset
132 (if (zerop (% msgnum 10))
a099f0c77321 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 131
diff changeset
133 (message "Finding sort keys...%d" msgnum))
90
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
134 (setq msgnum (1+ msgnum))))
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
135 (or reverse (setq sort-lists (nreverse sort-lists)))
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
136 (setq sort-lists
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
137 (sort sort-lists
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
138 (function
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
139 (lambda (a b)
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
140 (string-lessp (car a) (car b))))))
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
141 (if reverse (setq sort-lists (nreverse sort-lists)))
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
142 (message "Reordering buffer...")
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
143 (delete-region (rmail-msgbeg 1) (rmail-msgend rmail-total-messages))
148
a099f0c77321 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 131
diff changeset
144 (let ((msgnum 1))
a099f0c77321 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 131
diff changeset
145 (while sort-lists
a099f0c77321 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 131
diff changeset
146 (insert (cdr (car sort-lists)))
a099f0c77321 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 131
diff changeset
147 (if (zerop (% msgnum 10))
a099f0c77321 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 131
diff changeset
148 (message "Reordering buffer...%d" msgnum))
a099f0c77321 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 131
diff changeset
149 (setq sort-lists (cdr sort-lists))
a099f0c77321 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 131
diff changeset
150 (setq msgnum (1+ msgnum))))
90
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
151 (rmail-set-message-counters)
150
00792257e669 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 148
diff changeset
152 (rmail-show-message 1)))
90
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
153
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
154 (defun rmail-fetch-field (msg field)
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
155 "Return the value of the header field FIELD of MSG.
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
156 Arguments are MSG and FIELD."
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
157 (let ((next (rmail-msgend msg)))
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
158 (save-restriction
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
159 (goto-char (rmail-msgbeg msg))
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
160 (narrow-to-region (if (search-forward "\n*** EOOH ***\n" next t)
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
161 (point)
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
162 (forward-line 1)
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
163 (point))
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
164 (progn (search-forward "\n\n" nil t) (point)))
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
165 (mail-fetch-field field))))
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
166
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
167 ;; Copy of the function gnus-comparable-date in gnus.el
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
168
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
169 (defun rmail-sortable-date-string (date)
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
170 "Make sortable string by string-lessp from DATE."
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
171 (let ((month '(("JAN" . " 1")("FEB" . " 2")("MAR" . " 3")
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
172 ("APR" . " 4")("MAY" . " 5")("JUN" . " 6")
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
173 ("JUL" . " 7")("AUG" . " 8")("SEP" . " 9")
150
00792257e669 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 148
diff changeset
174 ("OCT" . "10")("NOV" . "11")("DEC" . "12")
00792257e669 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 148
diff changeset
175 ("JANUARY" . " 1") ("FEBRUARY" . " 2")
00792257e669 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 148
diff changeset
176 ("MARCH" . " 3") ("APRIL" . " 4")
00792257e669 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 148
diff changeset
177 ("MAY" . " 5") ("JUNE" . " 6")
00792257e669 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 148
diff changeset
178 ("JULY" . " 7") ("AUGUST" . " 8")
00792257e669 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 148
diff changeset
179 ("SEPTEMBER" " 9") ("OCTOBER" . "10")
00792257e669 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 148
diff changeset
180 ("NOVEMBER" "11") ("DECEMBER" . "12")))
90
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
181 (date (or date "")))
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
182 ;; Can understand the following styles:
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
183 ;; (1) 14 Apr 89 03:20:12 GMT
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
184 ;; (2) Fri, 17 Mar 89 4:01:33 GMT
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
185 (if (string-match
92
2b8bcdcca3a1 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 90
diff changeset
186 "\\([0-9]+\\) +\\([^ ,]+\\) +\\([0-9]+\\) +\\([0-9:]+\\)" date)
90
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
187 (concat
131
d4c523560fe8 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 92
diff changeset
188 ;; Year
d4c523560fe8 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 92
diff changeset
189 (rmail-date-full-year
d4c523560fe8 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 92
diff changeset
190 (substring date (match-beginning 3) (match-end 3)))
90
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
191 ;; Month
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
192 (cdr
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
193 (assoc
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
194 (upcase (substring date (match-beginning 2) (match-end 2))) month))
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
195 ;; Day
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
196 (format "%2d" (string-to-int
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
197 (substring date
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
198 (match-beginning 1) (match-end 1))))
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
199 ;; Time
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
200 (substring date (match-beginning 4) (match-end 4)))
2851
3b0a06fc7c4b (rmail-sortable-date-string): Handle date in format
Richard M. Stallman <rms@gnu.org>
parents: 1430
diff changeset
201
3b0a06fc7c4b (rmail-sortable-date-string): Handle date in format
Richard M. Stallman <rms@gnu.org>
parents: 1430
diff changeset
202 ;; Handles this format Fri May 10 21:51:55 1991
3b0a06fc7c4b (rmail-sortable-date-string): Handle date in format
Richard M. Stallman <rms@gnu.org>
parents: 1430
diff changeset
203 (if (string-match
3b0a06fc7c4b (rmail-sortable-date-string): Handle date in format
Richard M. Stallman <rms@gnu.org>
parents: 1430
diff changeset
204 " \\([a-z][a-z][a-z]\\) +\\([0-9]+\\) \\([0-9:]+\\) \\([0-9]+\\)" date)
3b0a06fc7c4b (rmail-sortable-date-string): Handle date in format
Richard M. Stallman <rms@gnu.org>
parents: 1430
diff changeset
205 (concat
3b0a06fc7c4b (rmail-sortable-date-string): Handle date in format
Richard M. Stallman <rms@gnu.org>
parents: 1430
diff changeset
206 ;; Year
3b0a06fc7c4b (rmail-sortable-date-string): Handle date in format
Richard M. Stallman <rms@gnu.org>
parents: 1430
diff changeset
207 (rmail-date-full-year
3b0a06fc7c4b (rmail-sortable-date-string): Handle date in format
Richard M. Stallman <rms@gnu.org>
parents: 1430
diff changeset
208 (substring date (match-beginning 4) (match-end 4)))
3b0a06fc7c4b (rmail-sortable-date-string): Handle date in format
Richard M. Stallman <rms@gnu.org>
parents: 1430
diff changeset
209 ;; Month
3b0a06fc7c4b (rmail-sortable-date-string): Handle date in format
Richard M. Stallman <rms@gnu.org>
parents: 1430
diff changeset
210 (cdr
3b0a06fc7c4b (rmail-sortable-date-string): Handle date in format
Richard M. Stallman <rms@gnu.org>
parents: 1430
diff changeset
211 (assoc
3b0a06fc7c4b (rmail-sortable-date-string): Handle date in format
Richard M. Stallman <rms@gnu.org>
parents: 1430
diff changeset
212 (upcase (substring date (match-beginning 1) (match-end 1))) month))
3b0a06fc7c4b (rmail-sortable-date-string): Handle date in format
Richard M. Stallman <rms@gnu.org>
parents: 1430
diff changeset
213 ;; Day
3b0a06fc7c4b (rmail-sortable-date-string): Handle date in format
Richard M. Stallman <rms@gnu.org>
parents: 1430
diff changeset
214 (format "%2d" (string-to-int
3b0a06fc7c4b (rmail-sortable-date-string): Handle date in format
Richard M. Stallman <rms@gnu.org>
parents: 1430
diff changeset
215 (substring date
3b0a06fc7c4b (rmail-sortable-date-string): Handle date in format
Richard M. Stallman <rms@gnu.org>
parents: 1430
diff changeset
216 (match-beginning 2) (match-end 2))))
3b0a06fc7c4b (rmail-sortable-date-string): Handle date in format
Richard M. Stallman <rms@gnu.org>
parents: 1430
diff changeset
217 ;; Time
3b0a06fc7c4b (rmail-sortable-date-string): Handle date in format
Richard M. Stallman <rms@gnu.org>
parents: 1430
diff changeset
218 (substring date (match-beginning 3) (match-end 3)))
3b0a06fc7c4b (rmail-sortable-date-string): Handle date in format
Richard M. Stallman <rms@gnu.org>
parents: 1430
diff changeset
219
90
92266e9b90bb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
220 ;; Cannot understand DATE string.
2851
3b0a06fc7c4b (rmail-sortable-date-string): Handle date in format
Richard M. Stallman <rms@gnu.org>
parents: 1430
diff changeset
221 date))))
131
d4c523560fe8 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 92
diff changeset
222
d4c523560fe8 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 92
diff changeset
223 (defun rmail-date-full-year (year-string)
d4c523560fe8 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 92
diff changeset
224 (if (<= (length year-string) 2)
d4c523560fe8 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 92
diff changeset
225 (concat "19" year-string)
d4c523560fe8 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 92
diff changeset
226 year-string))
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 150
diff changeset
227
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 150
diff changeset
228 (provide 'rmailsort)
658
7cbd4fcd8b0f *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 584
diff changeset
229
7cbd4fcd8b0f *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 584
diff changeset
230 ;;; rmailsort.el ends here