+ (t (error "`qmail-inject' reported unknown failure"))))))
+
+(defun wl-draft-parse-msg-id-list-string (string)
+ "Get msg-id list from STRING."
+ (let (msg-id-list)
+ (dolist (parsed-id (std11-parse-msg-ids-string string))
+ (when (eq (car parsed-id) 'msg-id)
+ (setq msg-id-list (cons (std11-msg-id-string parsed-id)
+ msg-id-list))))
+ (nreverse msg-id-list)))
+
+(defun wl-draft-std11-parse-addresses (lal)
+ (let ((ret (std11-parse-address lal)))
+ (if ret
+ (let ((dest (list (car ret))))
+ (setq lal (cdr ret))
+ (while (and (setq ret (std11-parse-ascii-token lal))
+ (string-equal (cdr (assq 'specials (car ret))) ",")
+ (setq ret (std11-parse-address (cdr ret)))
+ )
+ (setq dest (cons (car ret) dest))
+ (setq lal (cdr ret)))
+ (while (eq 'spaces (car (car lal)))
+ (setq lal (cdr lal)))
+ (if lal (error "Error while parsing address"))
+ (nreverse dest)))))
+
+(defun wl-draft-parse-mailbox-list (field &optional remove-group-list)
+ "Get mailbox list of FIELD from current buffer.
+The buffer is expected to be narrowed to just the headers of the message.
+If optional argument REMOVE-GROUP-LIST is non-nil, remove group list content
+from current buffer."
+ (save-excursion
+ (let ((case-fold-search t)
+ (inhibit-read-only t)
+ addresses address
+ mailbox-list beg seq has-group-list)
+ (goto-char (point-min))
+ (while (re-search-forward (concat "^" (regexp-quote field) "[\t ]*:")
+ nil t)
+ (setq beg (point))
+ (re-search-forward "^[^ \t]" nil 'move)
+ (beginning-of-line)
+ (skip-chars-backward "\n")
+ (setq seq (std11-lexical-analyze
+ (buffer-substring-no-properties beg (point))))
+ (setq addresses (wl-draft-std11-parse-addresses seq))
+ (while addresses
+ (cond ((eq (car (car addresses)) 'group)
+ (setq has-group-list t)
+ (setq mailbox-list
+ (nconc mailbox-list
+ (mapcar
+ 'std11-address-string
+ (nth 2 (car addresses))))))
+ ((eq (car (car addresses)) 'mailbox)
+ (setq address (nth 1 (car addresses)))
+ (setq mailbox-list
+ (nconc mailbox-list
+ (list
+ (std11-addr-to-string
+ (if (eq (car address) 'phrase-route-addr)
+ (nth 2 address)
+ (cdr address))))))))
+ (setq addresses (cdr addresses)))
+ (when (and remove-group-list has-group-list)
+ (delete-region beg (point))
+ (insert (wl-address-string-without-group-list-contents seq))))
+ mailbox-list)))
+
+(defun wl-draft-deduce-address-list (buffer header-start header-end)
+ "Get address list suitable for smtp RCPT TO:<address>.
+Group list content is removed if `wl-draft-remove-group-list-contents' is
+non-nil."
+ (let ((fields '("to" "cc" "bcc"))
+ (resent-fields '("resent-to" "resent-cc" "resent-bcc"))
+ (case-fold-search t)
+ addrs recipients)
+ (save-excursion
+ (save-restriction
+ (narrow-to-region header-start header-end)
+ (goto-char (point-min))
+ (save-excursion
+ (if (re-search-forward "^resent-to[\t ]*:" nil t)
+ (setq fields resent-fields)))
+ (while fields
+ (setq recipients
+ (nconc recipients
+ (wl-draft-parse-mailbox-list
+ (car fields)
+ wl-draft-remove-group-list-contents)))
+ (setq fields (cdr fields)))
+ recipients))))