Re: FW: Re: [exim] Easy Disclaimers with Exim?

Pàgina inicial
Delete this message
Reply to this message
Autor: Johann Spies
Data:  
A: exim-users
Assumpte: Re: FW: Re: [exim] Easy Disclaimers with Exim?
On Tue, Jul 12, 2005 at 10:39:19PM -0700, .|MoNK|Cucumber . wrote:
> The lot of you that choose to argue and insult those that wish to use
> appended disclaimers/footers are merely wasting peoples time.
>
> The fact of the matter is that companies do use disclaimers/footers, and it
> was a simple question regarding if it was possible with Exim.
>
> The thread is not a debate on whether or not to use them, just a how-to
> question.


I had to do this recently as part of an investigation into the
technicalities of disclaimers in our setup.

In /etc/exim4/conf.d/router/200_exim4-config_primary I have

smarthost:
  debug_print = "R: smarthost for $local_part@$domain"
  driver = manualroute
  domains = ! +local_domains
  transport = remote_smtp_smarthost
#  transport = ${if eq {$sender_address_domain}{sun.ac.za}\
#               {remote_smtp_filter}{remote_smtp}}
  route_list = * DCsmarthost byname
  host_find_failed = defer
  same_domain_copy_routing = yes
  no_more


To use the disclaimer, I uncomment the two commented lines and comment
the one above it: transport = remote_smtp_smarthost

I then created a file:
/etc/exim4/conf.d/transport/33_exim4-config_remote_smtp_disclaimer_smarthost
which contains:

remote_smtp_filter:
        #driver = pipe
        driver = smtp
        transport_filter = "/usr/local/bin/disclaimer"



The file /usr/local/bin/disclaimer was compiled from the attached
sources. You should edit the functions "disclaimer" and
"disclaimer-header" to suit you situation.

You need Ocaml to compile the sources and use "make" to create a
bytecode-compiled program or "make nc" to compile a native-code
program.

Regards
Johann
-- 
Johann Spies          Telefoon: 021-808 4036
Informasietegnologie, Universiteit van Stellenbosch


     "Let your character be free from the love of money,
      being content with what you have; for He Himself has
      said, "I will never desert you, nor will I ever
      forsake you."
                              Hebrews 13:5

OCAMLMAKEFILE=/usr/share/ocaml-tools/OCamlMakefile
SOURCES=disclaimer.ml
RESULT=disclaimer
LIBS=unix pcre netstring
INCDIRS=+pcre +netstring
OCAMLFLAGS=-labels
LIBDIRS=+pcre +netstring
include $(OCAMLMAKEFILE)



(* #require "unix";; *)
(* #require "pcre";; *)
(* #require "netstring";; *)


(* Description: *)

(* Receive email handed to the program by exim4 through stdin. *)

(* Add a disclaimer to the first < `Body b> of the email if there is no *)
(* header "US-dislaimer: added" in the email. *)

(* Add a header "US-dislcaimer: added" to the email *)

(* Hand the message back to exim4 *)
let disclaimer_added = ref false
let disclaimer = "\n\nVrywaring: Jy hoef eintlik net die e-pos self te gelees het. :)\nDisclaimer: If you are reading this you are wasting your time :)\n"
let disclaimerheader = "US-disclaimer"


(* Receive the message though stdin *)
(* let readmessage f = Netmime.read_mime_message (new Netstream.input_stream (new Netchannels.input_channel (open_in f))) *)
let readmessage () = Netmime.read_mime_message (new Netstream.input_stream (new Netchannels.input_channel stdin));;

(* Write the message though stdout *)
let writemessage mesg = Netmime.write_mime_message ~crlf:false (new Netchannels.output_channel stdout) mesg

(* Does this part of the message (or the whole message) have the structure:
    (<obj>, `Body <obj>) ?
*)


(* let testsimple x = match x with *)
(*     (headers,`Body bb) -> true *)
(*   | _ -> false *)


(* If so, unpack it into a header section (headers) and body (bb) *)

let getsimpleparts ( x: Netmime.complex_mime_message) = match x with
    (headers, `Body bb) -> headers, bb

| _ -> failwith "Invalid email-structure";;


(* Add header to header section *)
let add_header ( header: Netmime.mime_header ) =
header# update_field disclaimerheader "added"

(* Add dislaimer to body section *)

let add_disclaimer ( contents: Netmime.mime_body ) = 
  let s = contents # value ^ disclaimer in
    contents #set_value s


let handle_simple_message message = 
  let headers, contents = getsimpleparts message in
    match List.mem("US-disclaimer", "added") headers#fields with
    false -> add_header headers;
          add_disclaimer contents;
        writemessage message
      | true  -> disclaimer_added:=true;
              writemessage message


let handle ( mesg :  Netmime.complex_mime_message) = match mesg with
      (header,`Body bb) ->  handle_simple_message mesg

| (header, `Parts body) ->

      let rec aux body =
        match body with
        [] -> ()
      | (h2, `Body b)::_ ->
          if not (List.mem("US-disclaimer", "added") header#fields) then
        begin
          add_header header;
          add_disclaimer b;
        end
       | (_, `Parts l)::_ -> aux l
      in
        aux body;
    writemessage mesg


let _ = handle ( readmessage () )