[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [VM] Filter outgoing mail

From: blueman
Subject: Re: [VM] Filter outgoing mail
Date: Fri, 04 May 2012 17:27:46 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux)

blueman <address@hidden> writes:
> 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.

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

(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)"
        (with-current-buffer smtpmail-text-buffer
          (and (re-search-forward "\n\n" nil t)
                   (re-search-backward "^X-JJKFILTER:" nil t)
                         (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!")))))))

reply via email to

[Prev in Thread] Current Thread [Next in Thread]