Klimi's new dotfiles with stow.
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

73 рядки
2.5 KiB

4 роки тому
  1. ;;; smtpmail-async.el --- Send e-mail with smtpmail.el asynchronously -*- lexical-binding: t -*-
  2. ;; Copyright (C) 2012-2016 Free Software Foundation, Inc.
  3. ;; Author: John Wiegley <jwiegley@gmail.com>
  4. ;; Created: 18 Jun 2012
  5. ;; Keywords: email async
  6. ;; X-URL: https://github.com/jwiegley/emacs-async
  7. ;; This program is free software; you can redistribute it and/or
  8. ;; modify it under the terms of the GNU General Public License as
  9. ;; published by the Free Software Foundation; either version 2, or (at
  10. ;; your option) any later version.
  11. ;; This program is distributed in the hope that it will be useful, but
  12. ;; WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. ;; General Public License for more details.
  15. ;; You should have received a copy of the GNU General Public License
  16. ;; along with GNU Emacs; see the file COPYING. If not, write to the
  17. ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  18. ;; Boston, MA 02111-1307, USA.
  19. ;;; Commentary:
  20. ;; Send e-mail with smtpmail.el asynchronously. To use:
  21. ;;
  22. ;; (require 'smtpmail-async)
  23. ;;
  24. ;; (setq send-mail-function 'async-smtpmail-send-it
  25. ;; message-send-mail-function 'async-smtpmail-send-it)
  26. ;;
  27. ;; This assumes you already have smtpmail.el working.
  28. ;;; Code:
  29. (defgroup smtpmail-async nil
  30. "Send e-mail with smtpmail.el asynchronously"
  31. :group 'smptmail)
  32. (require 'async)
  33. (require 'smtpmail)
  34. (require 'message)
  35. (defvar async-smtpmail-before-send-hook nil
  36. "Hook running in the child emacs in `async-smtpmail-send-it'.
  37. It is called just before calling `smtpmail-send-it'.")
  38. (defun async-smtpmail-send-it ()
  39. (let ((to (message-field-value "To"))
  40. (buf-content (buffer-substring-no-properties
  41. (point-min) (point-max))))
  42. (message "Delivering message to %s..." to)
  43. (async-start
  44. `(lambda ()
  45. (require 'smtpmail)
  46. (with-temp-buffer
  47. (insert ,buf-content)
  48. (set-buffer-multibyte nil)
  49. ;; Pass in the variable environment for smtpmail
  50. ,(async-inject-variables
  51. "\\`\\(smtpmail\\|async-smtpmail\\|\\(user-\\)?mail\\)-\\|auth-sources\\|epg\\|nsm"
  52. nil "\\`\\(mail-header-format-function\\|smtpmail-address-buffer\\|mail-mode-abbrev-table\\)")
  53. (run-hooks 'async-smtpmail-before-send-hook)
  54. (smtpmail-send-it)))
  55. (lambda (&optional _ignore)
  56. (message "Delivering message to %s...done" to)))))
  57. (provide 'smtpmail-async)
  58. ;;; smtpmail-async.el ends here