Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Filter outgoing mail

7 views
Skip to first unread message

blueman

unread,
May 4, 2012, 9:11:08 AM5/4/12
to
I would like to filter my *outgoing* mail composed in 'vm'.
I want to do this from Emacs at the last possible moment before the
email leaves emacs/vm...

Specifically, I have a perl filter that I would like to run on each
email.

What is the best way to hook into vm here. I know I could use
vm-mail-send-hook but that is a bit klugey in that I would have to first
read and that write back the region itself. I was curious whether there
are any hooks and/or functions more amenable to filtering.

Thanks!

blueman

unread,
May 4, 2012, 5:27:46 PM5/4/12
to
Well, I wasn't able to find any hooks, but I solved my problem for now
by putting 'before' advice on the function smtpmail-via-smtp. That is
where the final changes are made to the email (including adding on mime
& content headers and stripping off the on RFC standard headers) before
it is actually sent.

The function I wrote is of the following form -- it can be adapted as
needed...

(defvar smtpmail-filter-email-command ""
"Command to run as filter in smtpmail-via-smtp function advice. Note: the
command must return 0 on success. (JJK).")

(defadvice smtpmail-via-smtp
(before smtpmail-via-smtp-filter-email nil activate)
"Run filter function 'smtpmail-filter-email-command' on outgoing email
if an only if the header 'X-JJKFILTER' is present in the header. Note
that header field is removed in the sent email.(JJK - advice)"
(save-excursion
(with-current-buffer smtpmail-text-buffer
(and (re-search-forward "\n\n" nil t)
(re-search-backward "^X-JJKFILTER:" nil t)
(progn
(delete-region (bol-point) (1+(eol-point)))
(unless (= (shell-command-on-region (point-min) (point-max) smtp-filter-email-command nil t) 0)
(error "ERROR: Failed to run smtpmail filter... sending aborted!")))))))

Uday Reddy

unread,
May 5, 2012, 3:18:25 AM5/5/12
to blueman, viewma...@nongnu.org
blueman writes:

> Well, I wasn't able to find any hooks, but I solved my problem for now
> by putting 'before' advice on the function smtpmail-via-smtp. That is
> where the final changes are made to the email (including adding on mime
> & content headers and stripping off the on RFC standard headers) before
> it is actually sent.

Hi JJK, I couldn't see why this can't be done in vm-mail-send-hook or its
senior, mail-send-hook.

Structurally, tagging this on to smtpmail isn't quite right because it has
nothing to do with smtpmail as such. It wouldn't fire if you use some other
mail sending mechanism.

Cheers,
Uday

blueman

unread,
Jun 4, 2012, 12:14:58 AM6/4/12
to
Uday Reddy <usr.vm...@gmail.com> writes:
> blueman writes:
>
>> Well, I wasn't able to find any hooks, but I solved my problem for now
>> by putting 'before' advice on the function smtpmail-via-smtp. That is
>> where the final changes are made to the email (including adding on mime
>> & content headers and stripping off the on RFC standard headers) before
>> it is actually sent.
>
> Hi JJK, I couldn't see why this can't be done in vm-mail-send-hook or its
> senior, mail-send-hook.

The problem is that those hooks come too early in the process before all
the headers and mimification is done.

> Structurally, tagging this on to smtpmail isn't quite right because it has
> nothing to do with smtpmail as such. It wouldn't fire if you use some other
> mail sending mechanism.

I agree but I couldn't find any earlier hooks and this was the only
"clean" (though non-natural) place I could add my code via 'advice'
without hacking into the actual vm routines themselves.

Basically, I wanted the ability to modify the outgoing email when the
header & body is complete and it is just about to be sent off to the
mail transfer agent whether smtpmail or anything else.

Unfortunately, I couldn't find a hook that gave access to the entire
final email header and body. If I am missing something, please enlighten
me.
0 new messages