<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1">
  <title></title>
</head>
<body text="#000000" bgcolor="#ffffff">
<br>
<br>
Peter C. Ndikuwera wrote:<br>
<blockquote type="cite"
 cite="mid1062141399.1959.3.camel@mufasa.ds.co.ug">
  <pre wrap="">Hi Daniel,

I have a fix which is really a hack. I'm sure it's the wrong way to do
it but it works for me. I've attached the relevant part of my
CustomConfig.pm.

Peter</pre>
</blockquote>
<br>
Peter / Steve,<br>
I've tried this one and it works for me (although the DB username and
password appear in the maillog!!! ;-)<br>
<br>
Dan<br>
<blockquote type="cite"
 cite="mid1062141399.1959.3.camel@mufasa.ds.co.ug">
  <pre wrap="">
On Wed, 2003-08-27 at 17:14, Daniel Bird wrote:
  </pre>
  <blockquote type="cite">
    <pre wrap="">Hi,
I noticed in the archives the same problem I'm having, but no solution:
I keep seeing this in the maillog:

Cannot insert row: MySQL server has gone away

I was wondering if anyone has had this problem and managed to find a fix?

Regards
--
____________________________________

Daniel Bird
Network &amp; Systems Manager
St. George's Hospital  Medical School
Tooting
London SW17 0RE

P: +44 20 8725 2897
F: +44 20 8725 3583
E: <a class="moz-txt-link-abbreviated" href="mailto:dan@sghms.ac.uk">dan@sghms.ac.uk</a>
____________________________________

Hex dump: Where witches put used curses...
"#define QUESTION ((bb) || !(bb)) - Shakespeare."
    </pre>
    <pre wrap="">
<hr width="90%" size="4">
###############
# SQL Logging #
###############

use DBI;
use Sys::Hostname;

sub InitSQLLogging {
}

sub EndSQLLogging {
}

sub SQLLogging {
                my($sth);
                my($hostname) = hostname;

                # Modify this as necessary for your configuration
                my($db_name) = "mailscanner";
                my($db_host) = "localhost";
                my($db_user) = "mailscanner";
                my($db_pass) = "mailscanner";

                MailScanner::Log::InfoLog("Initialising database connection database=$db_name;host=$db_host,$db_user,$db_pass");

                # Connect to the database
                my($dbh) = DBI-&gt;connect("DBI:mysql:database=$db_name;host=$db_host",
                                                                                                                $db_user, $db_pass,
                                                                                                                {PrintError =&gt; 0});

                # Sometimes this line needs to be uncommented. Go figure
                # MailScanner::Log::WarnLog($DBI::errstr);

                # Check if connection was successfull - if it isn't
                # then generate a warning and continue processing.
                if (!$dbh) {
                                MailScanner::Log::WarnLog("Unable to initialise database connection: %s", $DBI::errstr);
                                        return;
                        } else {
                                        # Prepare statement
                                        $sth = $dbh-&gt;prepare("INSERT INTO maillog VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)") or MailScanner::Log::WarnLog($DBI::errstr);
                        }

                MailScanner::Log::InfoLog("Finished initialising database connection");
                my($message) = @_;

                # Don't bother trying to do an insert if no message
                # is passed-in or if the database connection is down.
                MailScanner::Log::InfoLog("In SQL Logging msg=$message, dbh=$dbh");
                return unless $message;
                return unless defined $dbh;

                # Get rid of control chars and tidy-up SpamAssassin report
                my $spamreport = $message-&gt;{spamreport};
                $spamreport =~ s/\n/ /g;
                $spamreport =~ s/\t//g;

                # Get timestamp, and format it so it is suitable to use with MySQL
                my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime();
                my($timestamp) = sprintf("%d-%02d-%02d %02d:%02d:%02d",
                                                                                                                 $year+1900,$mon+1,$mday,$hour,$min,$sec);

                # Also print 1 line for each report about this message. These lines
                # contain all the info above, + the attachment filename and text of
                # each report.
                my($file, $text, @report_array);
                while(($file, $text) = each %{$message-&gt;{allreports}}) {
                                $file = "the entire message" if $file eq "";
                                # Use the sanitised filename to avoid problems caused by people forcing
                                # logging of attachment filenames which contain nasty SQL instructions.
                                $file = $message-&gt;{file2safefile}{$file} or $file;
                                $text =~ s/\n/ /;  # Make sure text report only contains 1 line
                                $text =~ s/\t/ /; # and no tab characters
                                push (@report_array, $text);
                }

                # Sanitize reports
                my $reports = join(",",@report_array);

                # Insert the data
                $sth-&gt;execute(
                                                                        $timestamp,
                                                                        $message-&gt;{id},
                                                                        $message-&gt;{size},
                                                                        $message-&gt;{from},
                                                                        join(',', @{$message-&gt;{to}}),
                                                                        $message-&gt;{subject},
                                                                        $message-&gt;{clientip},
                                                                        join(',', @{$message-&gt;{archiveplaces}}),
                                                                        $message-&gt;{isspam},
                                                                        $message-&gt;{ishigh},
                                                                        $message-&gt;{issaspam},
                                                                        $message-&gt;{isrblspam},
                                                                        $message-&gt;{spamwhitelisted},
                                                                        $message-&gt;{sascore},
                                                                        $spamreport,
                                                                        $message-&gt;{virusinfected},
                                                                        $message-&gt;{nameinfected},
                                                                        $message-&gt;{otherinfected},
                                                                        $reports,
                                                                        $hostname)
                                or MailScanner::Log::WarnLog("Cannot insert row: %s", $DBI::errstr);

                MailScanner::Log::InfoLog("Finished SQL Logging [$DBI::errstr]");

                $dbh-&gt;disconnect if defined $dbh;
                MailScanner::Log::InfoLog("Disconnected from the database");
}
    </pre>
  </blockquote>
</blockquote>
<br>
<pre class="moz-signature" cols="72">--
____________________________________

Daniel Bird
Network &amp; Systems Manager
St. George's Hospital  Medical School
Tooting
London SW17 0RE

P: +44 20 8725 2897
F: +44 20 8725 3583
E: <a class="moz-txt-link-abbreviated" href="mailto:dan@sghms.ac.uk">dan@sghms.ac.uk</a>
____________________________________

Hex dump: Where witches put used curses...
"#define QUESTION ((bb) || !(bb)) - Shakespeare." </pre>
</body>
</html>