diff options
author | Lars Ingebrigtsen <larsi@gnus.org> | 2012-02-09 23:42:12 +0100 |
---|---|---|
committer | Lars Ingebrigtsen <larsi@gnus.org> | 2012-02-09 23:42:12 +0100 |
commit | 4c7e65bf4f3fb9d24ec23f68047486c3c182ff65 (patch) | |
tree | b84674d1a59e99e203e6c8747b9b63ff2a60614f /lisp/mail/smtpmail.el | |
parent | f3934f6fef7316982750c311b27961bd31109baa (diff) | |
download | emacs-4c7e65bf4f3fb9d24ec23f68047486c3c182ff65.tar.gz |
Get the MAIL FROM from the From: header if no domain is configured
* mail/smtpmail.el (smtpmail-user-mail-address): New function.
(smtpmail-via-smtp): Use it, or fall back on the From address.
(smtpmail-send-it): Ditto.
Diffstat (limited to 'lisp/mail/smtpmail.el')
-rw-r--r-- | lisp/mail/smtpmail.el | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/lisp/mail/smtpmail.el b/lisp/mail/smtpmail.el index e3051fd0c9f..99283bebf9d 100644 --- a/lisp/mail/smtpmail.el +++ b/lisp/mail/smtpmail.el @@ -200,7 +200,10 @@ The list is in preference order.") ;; local binding in the mail buffer will take effect. (smtpmail-mail-address (or (and mail-specify-envelope-from (mail-envelope-from)) - user-mail-address)) + (smtpmail-user-mail-address) + (let ((from (mail-fetch-field "from"))) + (and from + (cadr (mail-extract-address-components from)))))) (smtpmail-code-conv-from (if enable-multibyte-characters (let ((sendmail-coding-system smtpmail-code-conv-from)) @@ -611,6 +614,15 @@ The list is in preference order.") (unless smtpmail-smtp-server (error "Couldn't contact an SMTP server")))) +(defun smtpmail-user-mail-address () + "Return `user-mail-address' if it's a valid email address." + (and user-mail-address + (let ((parts (split-string user-mail-address "@"))) + (and (= (length parts) 2) + ;; There's a dot in the domain name. + (string-match "\\." (cadr parts)) + user-mail-address)))) + (defun smtpmail-via-smtp (recipient smtpmail-text-buffer &optional ask-for-password) (unless smtpmail-smtp-server @@ -621,10 +633,16 @@ The list is in preference order.") (port smtpmail-smtp-service) ;; `smtpmail-mail-address' should be set to the appropriate ;; buffer-local value by the caller, but in case not: - (envelope-from (or smtpmail-mail-address - (and mail-specify-envelope-from - (mail-envelope-from)) - user-mail-address)) + (envelope-from + (or smtpmail-mail-address + (and mail-specify-envelope-from + (mail-envelope-from)) + (smtpmail-user-mail-address) + ;; Fall back on the From: header as the envelope From + ;; address. + (let ((from (mail-fetch-field "from"))) + (and from + (cadr (mail-extract-address-components from)))))) response-code process-buffer result |