mailpost.el 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. ;;
  2. ;; P O S T . E L
  3. ;;
  4. ;; Yet another mail interface. this for the rmail system to provide
  5. ;; the missing sendmail interface on systems without /usr/lib/sendmail,
  6. ;; but with /usr/uci/post.
  7. ;;
  8. ;; created by: Gary Delp <delp at huey.Udel.Edu>
  9. ;; Mon Jan 13 14:45:12 1986
  10. ;;
  11. ;;
  12. ;; (setq send-mail-function 'post-mail-send-it)
  13. (defun post-mail-send-it ()
  14. "\
  15. the MH -post interface for rmail-mail to call.
  16. to use it, include (setq send-mail-function 'post-mail-send-it) in site-init."
  17. (let ((errbuf (if mail-interactive
  18. (generate-new-buffer " post-mail errors")
  19. 0))
  20. (temfile "/tmp/,rpost")
  21. (tembuf (generate-new-buffer " post-mail temp"))
  22. (case-fold-search nil)
  23. delimline
  24. (mailbuf (current-buffer)))
  25. (unwind-protect
  26. (save-excursion
  27. (set-buffer tembuf)
  28. (erase-buffer)
  29. (insert-buffer-substring mailbuf)
  30. (goto-char (point-max))
  31. ;; require one newline at the end.
  32. (or (= (preceding-char) ?\n)
  33. (insert ?\n))
  34. ;; Change header-delimiter to be what post-mail expects.
  35. (goto-char (point-min))
  36. (search-forward (concat "\n" mail-header-separator "\n"))
  37. (replace-match "\n\n")
  38. (backward-char 1)
  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. (save-excursion
  67. (set-buffer errbuf)
  68. (erase-buffer))))
  69. (write-file (setq temfile (make-temp-name temfile)))
  70. (set-file-modes temfile 384)
  71. (apply 'call-process
  72. (append (list (if (boundp 'post-mail-program)
  73. post-mail-program
  74. "/usr/uci/lib/mh/post")
  75. nil errbuf nil
  76. "-nofilter" "-msgid")
  77. (if mail-interactive '("-watch") '("-nowatch"))
  78. (list temfile)))
  79. (if mail-interactive
  80. (save-excursion
  81. (set-buffer errbuf)
  82. (goto-char (point-min))
  83. (while (re-search-forward "\n\n* *" nil t)
  84. (replace-match "; "))
  85. (if (not (zerop (buffer-size)))
  86. (error "Sending...failed to %s"
  87. (buffer-substring (point-min) (point-max)))))))
  88. (kill-buffer tembuf)
  89. (if (bufferp errbuf)
  90. (switch-to-buffer errbuf)))))