emailemacselispemacs24gnus

rewrite outgoing messages/posts by external program/filter


I would like to rewrite fully composed emacs-gnus messages/posts (headers and body) by external filter (external program/script, STDIN to STDOUT).
How to do it?


Solution

  • Add your function to message-send-hook:

    (add-hook 'message-send-hook 'my-message-rewrite)
    (defun my-message-rewrite ()
      "Pipe the current message buffer through the command and replace it with the output."
      (shell-command-on-region (point-min) (point-max)
                               "my command line with args"
                               t t))
    

    Obviously you do not have to resort to a shell command, your lisp function can do much more.

    Notes:

    1. This hook is run "quite early"; you might want to use message-send-mail-hook instead - it is run "very late".

    2. Let me reiterate: you are swimming against the stream here. You do not want to do this. Please ask a separate question on emacs.SE describing what your perl script does and you will see how much easier it is to accomplish with Lisp.