bug#47616: 27.1; hardening mail-envelope-from

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

bug#47616: 27.1; hardening mail-envelope-from

Francesco Potortì-2
>(defun mail-envelope-from ()
>  "Return the envelope mail address to use when sending mail.
>This function uses `mail-envelope-from'."
>  (or (if (eq mail-envelope-from 'header)
>  (nth 1 (mail-extract-address-components
>  (save-restriction
>    (save-excursion
>      (goto-char (point-max))
>      (re-search-backward
>       (concat "^" (regexp-quote mail-header-separator) "\n")
>       nil t)
>      (narrow-to-region (point-min) (point))
>      (mail-fetch-field "From")))))
> mail-envelope-from)
>      user-mail-address))

This one is better (I had forgotten about mail-header-end)

(require 'sendmail)
(defun mail-envelope-from ()
  "Return the envelope mail address to use when sending mail.
This function uses `mail-envelope-from'."
  (or (if (eq mail-envelope-from 'header)
          (let ((from-field (save-restriction
                              (narrow-to-region (point-min) (mail-header-end))
                              (mail-fetch-field "From"))))
            (when from-field
              (nth 1 (mail-extract-address-components from-field))))
        mail-envelope-from)
      user-mail-address))