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?
Asked
Active
Viewed 40 times
1 Answers
1
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:
This hook is run "quite early"; you might want to use
message-send-mail-hook
instead - it is run "very late".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.

sds
- 58,617
- 29
- 161
- 278
-
My perl skills are much better than my (e)lisp skills :-) – AnFi Jul 16 '15 at 11:09
-
Once upon a time I said something like that too. I learned better since then. Lisp is so much more powerful, easier to use, to debug, to develop, to learn! – sds Jul 16 '15 at 12:37
-
It seems that the script receives onlt message body. I wanted to rewrite full message (headers & body) - sorry for lack of precision. – AnFi Jul 16 '15 at 17:35
-
Sorry, I expected classic "empty line" as header/body separator. Emacs-gnus uses something different :-) – AnFi Jul 16 '15 at 17:46
-
indeed, and this is yet another reason not to do what you are doing. – sds Jul 16 '15 at 17:46
-
1) `message-send-news-hook` fails with utf8 chars in message body 2) I wanted 2A) per newsgroup time zone in Date: header (e.g. different TZ for pl.* and uk.* posts ) 2B) Reply-To: header with +detail based based on Message-Id: – AnFi Jul 16 '15 at 18:13
-
I am not sure I quite understand your last comment - could you ask a separate question? – sds Jul 16 '15 at 18:57
-
https://stackoverflow.com/questions/22271533/per-newsgroup-timezone-in-date-header https://stackoverflow.com/questions/15310574/how-to-generate-dynamic-reply-to-based-on-message-id-detail – AnFi Jul 16 '15 at 19:35