X-Git-Url: https://code.delx.au/gnu-emacs-elpa/blobdiff_plain/d771dff727e5bfff833376b8592c043ad9937046..228ec4bb351a9e14e338b9cb09eeb4809957c909:/smtpmail-async.el diff --git a/smtpmail-async.el b/smtpmail-async.el index 4750ce6c5..6fcf287f4 100644 --- a/smtpmail-async.el +++ b/smtpmail-async.el @@ -1,10 +1,10 @@ -;;; smtpmail-async --- Send e-mail with smtpmail.el asynchronously +;;; smtpmail-async.el --- Send e-mail with smtpmail.el asynchronously -*- lexical-binding: t -*- -;; Copyright (C) 2012 John Wiegley +;; Copyright (C) 2012-2016 Free Software Foundation, Inc. ;; Author: John Wiegley ;; Created: 18 Jun 2012 -;; Version: 1.0 + ;; Keywords: email async ;; X-URL: https://github.com/jwiegley/emacs-async @@ -34,23 +34,39 @@ ;; ;; This assumes you already have smtpmail.el working. +;;; Code: + (defgroup smtpmail-async nil "Send e-mail with smtpmail.el asynchronously" :group 'smptmail) (require 'async) (require 'smtpmail) +(require 'message) + +(defvar async-smtpmail-before-send-hook nil + "Hook running in the child emacs in `async-smtpmail-send-it'. +It is called just before calling `smtpmail-send-it'.") (defun async-smtpmail-send-it () - (async-start - `(lambda () - (require 'smtpmail) - (with-temp-buffer - (insert ,(buffer-substring-no-properties (point-min) (point-max))) - ;; Pass in the variable environment for smtpmail - ,(async-inject-variables "\\`\\(smtpmail\\|\\(user-\\)?mail\\)-") - (smtpmail-send-it))) - 'ignore)) + (let ((to (message-field-value "To")) + (buf-content (buffer-substring-no-properties + (point-min) (point-max)))) + (message "Delivering message to %s..." to) + (async-start + `(lambda () + (require 'smtpmail) + (with-temp-buffer + (insert ,buf-content) + (set-buffer-multibyte nil) + ;; Pass in the variable environment for smtpmail + ,(async-inject-variables + "\\`\\(smtpmail\\|async-smtpmail\\|\\(user-\\)?mail\\)-\\|auth-sources\\|epg" + nil "\\`\\(mail-header-format-function\\|smtpmail-address-buffer\\|mail-mode-abbrev-table\\)") + (run-hooks 'async-smtpmail-before-send-hook) + (smtpmail-send-it))) + (lambda (&optional _ignore) + (message "Delivering message to %s...done" to))))) (provide 'smtpmail-async)