aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lisp/mail/mail-utils.el25
1 files changed, 16 insertions, 9 deletions
diff --git a/lisp/mail/mail-utils.el b/lisp/mail/mail-utils.el
index ebf2f617789..2dc5a7687b8 100644
--- a/lisp/mail/mail-utils.el
+++ b/lisp/mail/mail-utils.el
@@ -168,17 +168,18 @@ Usenet paths ending in an element that matches are removed also."
168 userids))) 168 userids)))
169 169
170;;;###autoload 170;;;###autoload
171(defun mail-fetch-field (field-name &optional last all) 171(defun mail-fetch-field (field-name &optional last all list)
172 "Return the value of the header field FIELD-NAME. 172 "Return the value of the header field FIELD-NAME.
173The buffer is expected to be narrowed to just the headers of the message. 173The buffer is expected to be narrowed to just the headers of the message.
174If second arg LAST is non-nil, use the last such field if there are several. 174If second arg LAST is non-nil, use the last such field if there are several.
175If third arg ALL is non-nil, concatenate all such fields with commas between." 175If third arg ALL is non-nil, concatenate all such fields with commas between.
176If 4th arg LIST is non-nil, return a list of all such fields."
176 (save-excursion 177 (save-excursion
177 (goto-char (point-min)) 178 (goto-char (point-min))
178 (let ((case-fold-search t) 179 (let ((case-fold-search t)
179 (name (concat "^" (regexp-quote field-name) "[ \t]*:[ \t]*"))) 180 (name (concat "^" (regexp-quote field-name) "[ \t]*:[ \t]*")))
180 (if all 181 (if (or all list)
181 (let ((value "")) 182 (let ((value (if all "")))
182 (while (re-search-forward name nil t) 183 (while (re-search-forward name nil t)
183 (let ((opoint (point))) 184 (let ((opoint (point)))
184 (while (progn (forward-line 1) 185 (while (progn (forward-line 1)
@@ -186,11 +187,17 @@ If third arg ALL is non-nil, concatenate all such fields with commas between."
186 ;; Back up over newline, then trailing spaces or tabs 187 ;; Back up over newline, then trailing spaces or tabs
187 (forward-char -1) 188 (forward-char -1)
188 (skip-chars-backward " \t" opoint) 189 (skip-chars-backward " \t" opoint)
189 (setq value (concat value 190 (if list
190 (if (string= value "") "" ", ") 191 (setq value (cons (buffer-substring-no-properties
191 (buffer-substring-no-properties 192 opoint (point))
192 opoint (point)))))) 193 value))
193 (and (not (string= value "")) value)) 194 (setq value (concat value
195 (if (string= value "") "" ", ")
196 (buffer-substring-no-properties
197 opoint (point)))))))
198 (if list
199 value
200 (and (not (string= value "")) value)))
194 (if (re-search-forward name nil t) 201 (if (re-search-forward name nil t)
195 (progn 202 (progn
196 (if last (while (re-search-forward name nil t))) 203 (if last (while (re-search-forward name nil t)))