annotate lisp/utils/mail-utils.el @ 0:376386a54a3c r19-14

Import from CVS: tag r19-14
author cvs
date Mon, 13 Aug 2007 08:45:50 +0200
parents
children 0293115a14e9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;; mail-utils.el --- utility functions used both by rmail and rnews
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 ;; Copyright (C) 1985 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;; Maintainer: FSF
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;; Keywords: mail, news
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 ;; This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;; XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;; under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;; XEmacs is distributed in the hope that it will be useful, but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;; General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;; along with XEmacs; see the file COPYING. If not, write to the Free
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 ;; Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 ;;; Synched up with: FSF 19.30.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 ;;; Commentary:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 ;; Utility functions for mail and netnews handling. These handle fine
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 ;; points of header parsing.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 ;;; Code:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 ;;; We require lisp-mode to make sure that lisp-mode-syntax-table has
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 ;;; been initialized.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 (require 'lisp-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 (defvar mail-use-rfc822 nil "\
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 *If non-nil, use a full, hairy RFC822 parser on mail addresses.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 Otherwise, (the default) use a smaller, somewhat faster, and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 often correct parser.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 ;; Returns t if file FILE is an Rmail file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 (defun mail-file-babyl-p (file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 (let ((buf (generate-new-buffer " *rmail-file-p*")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 (set-buffer buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 (insert-file-contents file nil 0 100)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 (looking-at "BABYL OPTIONS:"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 (kill-buffer buf))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 (defun mail-string-delete (string start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 "Returns a string containing all of STRING except the part
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 from START (inclusive) to END (exclusive)."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 (if (null end) (substring string 0 start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 (concat (substring string 0 start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 (substring string end nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 (defun mail-strip-quoted-names (address)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 "Delete comments and quoted strings in an address list ADDRESS.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 Also delete leading/trailing whitespace and replace FOO <BAR> with just BAR.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 Return a modified address list."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 (if (null address)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 (if mail-use-rfc822
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 (progn (require 'rfc822)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 (mapconcat 'identity (rfc822-addresses address) ", "))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 (let (pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 (string-match "\\`[ \t\n]*" address)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 ;; strip surrounding whitespace
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 (setq address (substring address
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 (match-end 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 (string-match "[ \t\n]*\\'" address
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 (match-end 0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 ;; Detect nested comments.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 (if (string-match "[ \t]*(\\([^)\"\\]\\|\\\\.\\|\\\\\n\\)*(" address)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 ;; Strip nested comments.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 (set-buffer (get-buffer-create " *temp*"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 (erase-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 (insert address)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 (set-syntax-table lisp-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 (goto-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 (while (search-forward "(" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 (forward-char -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 (skip-chars-backward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 (delete-region (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 (condition-case ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 (forward-sexp 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 (error (goto-char (point-max))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 (setq address (buffer-string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 (erase-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 ;; Strip non-nested comments an easier way.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 (while (setq pos (string-match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 ;; This doesn't hack rfc822 nested comments
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 ;; `(xyzzy (foo) whinge)' properly. Big deal.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 "[ \t]*(\\([^)\"\\]\\|\\\\.\\|\\\\\n\\)*)"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 address))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 (setq address
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 (mail-string-delete address
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 pos (match-end 0)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 ;; strip `quoted' names (This is supposed to hack `"Foo Bar" <bar@host>')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 (setq pos 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 (while (setq pos (string-match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 "[ \t]*\"\\([^\"\\]\\|\\\\.\\|\\\\\n\\)*\"[ \t\n]*"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 address pos))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 ;; If the next thing is "@", we have "foo bar"@host. Leave it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 (if (and (> (length address) (match-end 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 (= (aref address (match-end 0)) ?@))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 (setq pos (match-end 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 (setq address
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 (mail-string-delete address
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 pos (match-end 0)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 ;; Retain only part of address in <> delims, if there is such a thing.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 (while (setq pos (string-match "\\(,\\s-*\\|\\`\\)[^,]*<\\([^>,]*>\\)"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 address))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 (let ((junk-beg (match-end 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 (junk-end (match-beginning 2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 (close (match-end 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 (setq address (mail-string-delete address (1- close) close))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 (setq address (mail-string-delete address junk-beg junk-end))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 address))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 (or (and (boundp 'rmail-default-dont-reply-to-names)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 (not (null rmail-default-dont-reply-to-names)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 (setq rmail-default-dont-reply-to-names "info-"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 ; rmail-dont-reply-to-names is defined in loaddefs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 (defun rmail-dont-reply-to (userids)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 "Returns string of mail addresses USERIDS sans any recipients
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 that start with matches for `rmail-dont-reply-to-names'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 Usenet paths ending in an element that matches are removed also."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 (if (null rmail-dont-reply-to-names)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 (setq rmail-dont-reply-to-names
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 (concat (if rmail-default-dont-reply-to-names
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 (concat rmail-default-dont-reply-to-names "\\|")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 (concat (regexp-quote (user-login-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 "\\>"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 (let ((match (concat "\\(^\\|,\\)[ \t\n]*\\([^,\n]*!\\|\\)\\("
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 rmail-dont-reply-to-names
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 "\\)"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 (case-fold-search t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 pos epos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 (while (setq pos (string-match match userids))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 (if (> pos 0) (setq pos (match-beginning 2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 (setq epos
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 ;; Delete thru the next comma, plus whitespace after.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 (if (string-match ",[ \t\n]+" userids (match-end 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 (match-end 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 (length userids)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 (setq userids
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 (mail-string-delete
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 userids pos epos)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 ;; get rid of any trailing commas
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 (if (setq pos (string-match "[ ,\t\n]*\\'" userids))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 (setq userids (substring userids 0 pos)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 ;; remove leading spaces. they bother me.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 (if (string-match "\\s *" userids)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 (substring userids (match-end 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 userids)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 (defun mail-fetch-field (field-name &optional last all)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 "Return the value of the header field FIELD-NAME.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 The buffer is expected to be narrowed to just the headers of the message.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 If second arg LAST is non-nil, use the last such field if there are several.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 If third arg ALL is non-nil, concatenate all such fields with commas between."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 (let ((case-fold-search t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 (name (concat "^" (regexp-quote field-name) "[ \t]*:[ \t]*")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 (if all
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 (let ((value ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 (while (re-search-forward name nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 (let ((opoint (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 (while (progn (forward-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 (looking-at "[ \t]")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 ;; Back up over newline, then trailing spaces or tabs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 (forward-char -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 (while (member (preceding-char) '(? ?\t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 (forward-char -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 (setq value (concat value
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 (if (string= value "") "" ", ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 (buffer-substring-no-properties
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 opoint (point))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 (and (not (string= value "")) value))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 (if (re-search-forward name nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 (if last (while (re-search-forward name nil t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 (let ((opoint (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 (while (progn (forward-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 (looking-at "[ \t]")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 ;; Back up over newline, then trailing spaces or tabs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 (forward-char -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 (while (member (preceding-char) '(? ?\t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 (forward-char -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 (buffer-substring-no-properties opoint (point)))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 ;; Parse a list of tokens separated by commas.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 ;; It runs from point to the end of the visible part of the buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 ;; Whitespace before or after tokens is ignored,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 ;; but whitespace within tokens is kept.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 (defun mail-parse-comma-list ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 (let (accumulated
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 beg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 (skip-chars-forward " ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 (while (not (eobp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 (setq beg (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 (skip-chars-forward "^,")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 (skip-chars-backward " ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 (setq accumulated
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 (cons (buffer-substring beg (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 accumulated))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 (skip-chars-forward "^,")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 (skip-chars-forward ", "))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 accumulated))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 (defun mail-comma-list-regexp (labels)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 (let (pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 (setq pos (or (string-match "[^ \t]" labels) 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 ;; Remove leading and trailing whitespace.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 (setq labels (substring labels pos (string-match "[ \t]*$" labels pos)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 ;; Change each comma to \|, and flush surrounding whitespace.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 (while (setq pos (string-match "[ \t]*,[ \t]*" labels))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 (setq labels
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 (concat (substring labels 0 pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 "\\|"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 (substring labels (match-end 0))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 labels)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 (defun mail-rfc822-time-zone (time)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 (let* ((sec (or (car (current-time-zone time)) 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 (absmin (/ (abs sec) 60)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 (format "%c%02d%02d" (if (< sec 0) ?- ?+) (/ absmin 60) (% absmin 60))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 (defun mail-rfc822-date ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 (let* ((time (current-time))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 (s (current-time-string time)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 (string-match "[^ ]+ +\\([^ ]+\\) +\\([^ ]+\\) \\([^ ]+\\) \\([^ ]+\\)" s)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 (concat (substring s (match-beginning 2) (match-end 2)) " "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 (substring s (match-beginning 1) (match-end 1)) " "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 (substring s (match-beginning 4) (match-end 4)) " "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 (substring s (match-beginning 3) (match-end 3)) " "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 (mail-rfc822-time-zone time))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 (provide 'mail-utils)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 ;;; mail-utils.el ends here