mailpost.el 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. ;;; mailpost.el --- RMAIL coupler to /usr/uci/post mailer
  2. ;; This is in the public domain
  3. ;; since Delp distributed it in 1986 without a copyright notice.
  4. ;; This file is part of GNU Emacs.
  5. ;; Author: Gary Delp <delp@huey.Udel.Edu>
  6. ;; Maintainer: FSF
  7. ;; Created: 13 Jan 1986
  8. ;; Keywords: mail
  9. ;;; Commentary:
  10. ;; Yet another mail interface. this for the rmail system to provide
  11. ;; the missing sendmail interface on systems without /usr/lib/sendmail,
  12. ;; but with /usr/uci/post.
  13. ;;; Code:
  14. (require 'mailalias)
  15. (require 'sendmail)
  16. ;; (setq send-mail-function 'post-mail-send-it)
  17. (defun post-mail-send-it ()
  18. "The MH -post interface for `rmail-mail' to call.
  19. To use it, include \"(setq send-mail-function 'post-mail-send-it)\" in
  20. site-init."
  21. (let ((errbuf (if mail-interactive
  22. (generate-new-buffer " post-mail errors")
  23. 0))
  24. temfile
  25. (tembuf (generate-new-buffer " post-mail temp"))
  26. (case-fold-search nil)
  27. delimline
  28. (mailbuf (current-buffer)))
  29. (unwind-protect
  30. (with-current-buffer tembuf
  31. (erase-buffer)
  32. (insert-buffer-substring mailbuf)
  33. (goto-char (point-max))
  34. ;; require one newline at the end.
  35. (or (= (preceding-char) ?\n)
  36. (insert ?\n))
  37. ;; Change header-delimiter to be what post-mail expects.
  38. (mail-sendmail-undelimit-header)
  39. (setq delimline (point-marker))
  40. (if mail-aliases
  41. (expand-mail-aliases (point-min) delimline))
  42. (goto-char (point-min))
  43. ;; ignore any blank lines in the header
  44. (while (and (re-search-forward "\n\n\n*" delimline t)
  45. (< (point) delimline))
  46. (replace-match "\n"))
  47. ;; Find and handle any FCC fields.
  48. (let ((case-fold-search t))
  49. (goto-char (point-min))
  50. (if (re-search-forward "^FCC:" delimline t)
  51. (mail-do-fcc delimline))
  52. ;; If there is a From and no Sender, put it a Sender.
  53. (goto-char (point-min))
  54. (and (re-search-forward "^From:" delimline t)
  55. (not (save-excursion
  56. (goto-char (point-min))
  57. (re-search-forward "^Sender:" delimline t)))
  58. (progn
  59. (forward-line 1)
  60. (insert "Sender: " (user-login-name) "\n")))
  61. ;; don't send out a blank subject line
  62. (goto-char (point-min))
  63. (if (re-search-forward "^Subject:[ \t]*\n" delimline t)
  64. (replace-match ""))
  65. (if mail-interactive
  66. (with-current-buffer errbuf
  67. (erase-buffer))))
  68. (let ((m (default-file-modes)))
  69. (unwind-protect
  70. (progn
  71. (set-default-file-modes 384)
  72. (setq temfile (make-temp-file ",rpost")))
  73. (set-default-file-modes m)))
  74. (apply 'call-process
  75. (append (list (if (boundp 'post-mail-program)
  76. post-mail-program
  77. "/usr/uci/lib/mh/post")
  78. nil errbuf nil
  79. "-nofilter" "-msgid")
  80. (if mail-interactive '("-watch") '("-nowatch"))
  81. (list temfile)))
  82. (if mail-interactive
  83. (with-current-buffer errbuf
  84. (goto-char (point-min))
  85. (while (re-search-forward "\n\n* *" nil t)
  86. (replace-match "; "))
  87. (if (not (zerop (buffer-size)))
  88. (error "Sending...failed to %s"
  89. (buffer-substring (point-min) (point-max)))))))
  90. (kill-buffer tembuf)
  91. (if (bufferp errbuf)
  92. (switch-to-buffer errbuf)))))
  93. (provide 'mailpost)
  94. ;;; mailpost.el ends here