annotate lisp/utils/mail-utils.el @ 98:0d2f883870bc r20-1b1

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