home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / languages / elisp / misc / mmdf.el < prev    next >
Encoding:
Text File  |  1993-06-14  |  4.2 KB  |  142 lines

  1. ;; LCD Archive Entry:
  2. ;; mmdf|Scott Michel|scottm@intime.com|
  3. ;; Alternative to sendmail-send-it, IFF you use MMDF mail transport.|
  4. ;; 30-Nov-1992||~/misc/mmdf.el.Z|
  5.  
  6. ;; GNU Emacs is free software; you can redistribute it and/or modify
  7. ;; it under the terms of the GNU General Public License as published by
  8. ;; the Free Software Foundation; either version 1, or (at your option)
  9. ;; any later version.
  10.  
  11. ;; GNU Emacs is distributed in the hope that it will be useful,
  12. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. ;; GNU General Public License for more details.
  15.  
  16. ;; You should have received a copy of the GNU General Public License
  17. ;; along with GNU Emacs; see the file COPYING.  If not, write to
  18. ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  19. ;;
  20. ;; MMDF mail sender.
  21. ;; Written by scottm (Scott Michel, scottm@intime.com)
  22. ;; 30 Nov 92
  23. ;;
  24. ;; This is an alternative to sendmail-send-it, IFF you use MMDF as your
  25. ;; primary mail transport.
  26. ;;
  27. ;; Installation:
  28. ;;
  29. ;; 1. Somewhere in your load-path, put mmdf.el
  30. ;; 2. Byte compile it, producing mmdf.elc
  31. ;; 3. In your .emacs, you should set the following:
  32. ;;
  33. ;; (autoload 'mmdf-send-it "mmdf" "Load MMDF mail transport program" nil)
  34. ;; (setq send-mail-function 'mmdf-send-it)
  35. ;;
  36. ;; 4. Use and enjoy
  37. ;;
  38. ;; scottm
  39.  
  40. (provide 'mmdf)
  41.  
  42. (if (or (not (boundp 'sendmail-program))
  43.     (equal sendmail-program "/usr/lib/sendmail")
  44.     (equal sendmail-program "fakemail"))
  45.     (setq sendmail-program "/usr/mmdf/bin/submit"))
  46.  
  47. (defun mmdf-send-it ()
  48.   (message "MMDF transporting...")
  49.   (let ((errbuf (generate-new-buffer "*MMDF errors*"))
  50.     (tembuf (generate-new-buffer "*MMDF temp*"))
  51.     (case-fold-search nil)
  52.     delimline
  53.     (mailbuf (current-buffer)))
  54.     (unwind-protect
  55.     (save-excursion
  56.       (set-buffer tembuf)
  57.       (setq buffer-undo-list t)
  58.       (erase-buffer)
  59.       (insert-buffer-substring mailbuf)
  60.       (goto-char (point-max))
  61.       ;; require one newline at the end.
  62.       (or (= (preceding-char) ?\n)
  63.           (insert ?\n))
  64.       ;;
  65.       ;; *** Departure from sendmail: Instead of retaining the extra
  66.       ;; To: and Subject: lines, we kill the mail-header-separator line
  67.       ;;
  68.       (goto-char (point-min))
  69.       (re-search-forward
  70.        (concat "^" (regexp-quote mail-header-separator) "\n"))
  71.       (forward-line -1)
  72.       (kill-line)
  73.       (setq delimline (point-marker))
  74.       (if mail-aliases
  75.           (expand-mail-aliases (point-min) delimline))
  76.       
  77.       ;; ignore any blank lines in the header
  78.       (goto-char (point-min))
  79.       (while (and (re-search-forward "\n\n\n*" delimline t)
  80.               (< (point) delimline))
  81.         (replace-match "\n"))
  82.       
  83.       (let ((case-fold-search t))
  84.         ;;
  85.         ;; Make sure that there is a "From:" line, otherwise MMDF barks.
  86.         ;;
  87.         (goto-char (point-min))
  88.         (and (not (re-search-forward "^From:" delimline t))
  89.          (progn
  90.            (goto-char delimline)
  91.            (insert "From: " (user-login-name) "\n")))
  92.         
  93.         ;;
  94.         ;; Find and handle any FCC fields.
  95.         ;;
  96.         (goto-char (point-min))
  97.         (if (re-search-forward "^FCC:" delimline t)
  98.         (mail-do-fcc delimline))
  99.         
  100.         ;;
  101.         ;; If there is a From and no Sender, put it a Sender.
  102.         ;;
  103.         
  104.         (goto-char (point-min))
  105.         (and (re-search-forward "^From:"  delimline t)
  106.          (not (save-excursion
  107.             (goto-char (point-min))
  108.             (re-search-forward "^Sender:" delimline t)))
  109.          (progn
  110.            (forward-line 1)
  111.            (insert "Sender: " (user-login-name) "\n")))
  112.         
  113.         ;;
  114.         ;; don't send out a blank subject line
  115.         ;;
  116.         (goto-char (point-min))
  117.         (if (re-search-forward "^Subject:[ \t]*\n" delimline t)
  118.         (replace-match ""))
  119.         (if mail-interactive
  120.         (save-excursion
  121.           (set-buffer errbuf)
  122.           (erase-buffer))))
  123.       
  124.       (if (apply 'call-process-region
  125.              (list (point-min) (point-max)
  126.                (if (boundp 'sendmail-program)
  127.                    sendmail-program "/usr/mmdf/bin/submit")
  128.                nil errbuf nil "-mlrnxto,cc\*"))
  129.           (progn
  130.         (save-excursion
  131.           (set-buffer errbuf)
  132.           (goto-char (point-min))
  133.           (while (re-search-forward "\n\n* *" nil t)
  134.             (replace-match "; "))
  135.           (if (not (zerop (buffer-size)))
  136.               (error "Sending...failed to %s"
  137.                  (buffer-substring (point-min) (point-max))))))))
  138.       (kill-buffer tembuf)
  139.       (if (bufferp errbuf)
  140.       (kill-buffer errbuf))))
  141.   (message "MMDF tranported message."))
  142.