[Mimedefang] md_check_against_smtp_server and md_graphdefang_log

Matt Garretson mattg at assembly.state.ny.us
Wed Mar 27 15:21:42 EDT 2013

On 3/27/2013 12:41 PM, James Curtis wrote:
> Can't imagine the amount of errors I'll incur when creating a new
> sub-routine for my_graphdefang_log(), but it will be a fun time.  I'm
> assuming that I start with the code from md_graphdefang_log and
> remove the variables.

Precisely. I'd suggest adding the new function to your filter instead
of modifying mimedefang.pl . Also, note this excerpt from the
mimedefang.pl man page:

       You are strongly recommended to test your filter before
  installing it in /etc/mail/mimedefang-filter.  To test the filter,
  save it in a file (e.g. test-filter) and run this command:

            mimedefang.pl -f test-filter -test

       This  tests  the filter for syntactic correctness.  If it
  passes, you can install it as a production filter.  (Note that the
  test tests only for correct Perl syntax; it doesn’t make sure your
  filter does something sensible.)

As a simple example, you could start with something like this, which is
basically a stripped-down md_graphdefang_log():

sub my_graphdefang_log($;$$)
    return unless defined($GraphDefangSyslogFacility);

    my $event = shift;
    my $value1 = shift;
    my $value2 = shift;

    $value1 = "" unless defined($value1);
    $value2 = "" unless defined($value2);

    # Make values safe for graphdefang
    $event = percent_encode_for_graphdefang($event);
    $value1 = percent_encode_for_graphdefang($value1);
    $value2 = percent_encode_for_graphdefang($value2);

    md_syslog("$GraphDefangSyslogFacility|info","MYLOG,_NOMSGID_," .

That should work from filter_relay() onwards.  It's up to you what you
want to log, as long as you don't try to access any variables that are
not defined in the current state of the milter.

More information about the MIMEDefang mailing list