Goldfish Problem

46 views
Skip to first unread message

rated-x

unread,
Jul 6, 2009, 2:49:35 AM7/6/09
to goldfish-user

Hi All,

All other email client dont have problem with the autoresponder
i found out why it wont sent to the right person
because some squirrelmail dont have "less than" and "greater than"
symbol
in the From: part of the message and when i look at your code that it
would trim
the lessthan and greaterthan symbol.



foreach ($mail as $line)
{
$line = trim
($line);

if (substr
($line, 0, 5) == 'From:')
{

$address = substr($line, strpos($line, '<') + 1, strpos($line, '>') -
strpos($line, '<')-1)."\n";
break;
}
}



Squirrelmail Format:

Date: Mon, 6 Jul 2009 13:03:17 +0800 (PHT)
Subject: yyyy
From: test...@mydomain.com.ph
To: joh...@mydomain.com.ph

User-Agent: SquirrelMail/1.4.13
MIME-Version: 1.0


Google and other mail client format:

Date: Mon, 6 Jul 2009 13:47:31 +0800
Message-ID:
<334bda060907052247h485...@mail.gmail.com>
Subject: czczxczxc
From: John Ray Abamonga <joh...@gmail.com>
To: joh...@mydomain.com.ph
Content-Type: multipart/alternative;
boundary=00163691fe62cbd540046e030a16

--00163691fe62cbd540046e030a16


hope you can help me i been testing series of codes modyfing yet im
confuse
on that part :)

paolinux

unread,
Jul 6, 2009, 9:38:42 AM7/6/09
to goldfish-user
Hi,
I take a look to the piece of code on the autoresponder.php. The
problem is not about the email address I insert from squirrelmail, but
about the From field the email file has.

I think a control on the "less than" and "greater than" symbol is
needed.

ciao Paolo



On Jul 6, 8:49 am, rated-x <johnray.abamo...@gmail.com> wrote:
> Hi All,
>
> All other email client dont have problem with the autoresponder
> i found out why it wont sent to the right person
> because some squirrelmail dont have "less than" and "greater than"
> symbol
> in the From: part of the message and when i look at your code that it
> would trim
> the lessthan and greaterthan symbol.
>
> foreach ($mail as $line)
>                                         {
>                                                         $line = trim
> ($line);
>
>                                                         if (substr
> ($line, 0, 5) == 'From:')
>                                                         {
>
> $address = substr($line, strpos($line, '<') + 1, strpos($line, '>') -
> strpos($line, '<')-1)."\n";
>                                                         break;
>                                                         }
>                                         }
>
> Squirrelmail Format:
>
> Date: Mon, 6 Jul 2009 13:03:17 +0800 (PHT)
> Subject: yyyy
> From: testu...@mydomain.com.ph
> To: john...@mydomain.com.ph
>
> User-Agent: SquirrelMail/1.4.13
> MIME-Version: 1.0
>
> Google and other mail client format:
>
> Date: Mon, 6 Jul 2009 13:47:31 +0800
> Message-ID:
> <334bda060907052247h4859b99crf145a6cb8d26e...@mail.gmail.com>
> Subject: czczxczxc
> From: John Ray Abamonga <john...@gmail.com>
> To: john...@mydomain.com.ph

John Ray Abamonga

unread,
Jul 6, 2009, 9:47:36 AM7/6/09
to goldfi...@googlegroups.com

ok but how >.< im so confused now the autoresponder is working fine but when the person
sending me is using squirrelmail  it wont trim properly because of the less and greater than
sign..

paolinux

unread,
Jul 6, 2009, 4:40:26 PM7/6/09
to goldfish-user
Hi John,
try to use the autoreponder I attach to this post:

-------------------------------------------------------------------------------------------------------------------------

#!/usr/bin/php -q
<?
/*
goldfish - the PHP auto responder for postfix
Copyright (C) 2007-2008 by Remo Fritzsche

This program is free software: you can redistribute it and/or
modify
it under the terms of the GNU General Public License as published
by
the Free Software Foundation, either version 3 of the License, or
any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/
licenses/>.

(c) 2007-2009 Remo Fritzsche (Main application programmer)
(c) 2009 Karl Herrick (Bugfix)
(c) 2007-2008 Manuel Aller (Additional programming)

Version 1.0-STABLE
*/

ini_set('display_errors', true);
error_reporting( E_ALL );

######################################
# Check PHP version #
######################################

if ( version_compare( PHP_VERSION, "5.0.0" ) == - 1 )
{
echo "Error, you are currently not running PHP 5 or later. Exiting.
\n";
exit;
}

######################################
# Configuration #
######################################
/* General */
$conf['cycle'] = 5 * 60;

/* Logging */
$conf['log_file_path'] = "/var/log/goldfish";
$conf['write_log'] = true;

/* Database information */
$conf['mysql_host'] = "localhost";
$conf['mysql_user'] = "myuser";
$conf['mysql_password'] = "mypassword";
$conf['mysql_database'] = "mailserver";

/* Database Queries */

# This query has to return the path (`path`) of the corresponding
# maildir-Mailbox with email-address %m
$conf['q_mailbox_path'] = "SELECT CONCAT('/home/vmail/',
SUBSTRING_INDEX(email,'@',-1), '/', SUBSTRING_INDEX(email,'@',1), '/')
as `path` FROM view_users WHERE `email` = '%m'";

# This query has to return the following fields from the
autoresponder table: `from`, `to`, `email`, `message` where `enabled`
= 2
$conf['q_forwardings'] = "SELECT * FROM `autoresponder` WHERE
`enabled` = 1";

# This query has to disable every autoresponder entry which ended
in the past
$conf['q_disable_forwarding'] = "UPDATE `autoresponder` SET
`enabled` = 0 WHERE `to` < CURDATE();";

# This query has to activate every autoresponder entry which
starts today
$conf['q_enable_forwarding'] = "UPDATE `autoresponder` SET
`enabled` = 1 WHERE `from` = CURDATE();";

# This query has to return the message of an autoresponder entry
identified by email %m
$conf['q_messages'] = "SELECT `message` FROM `autoresponder` WHERE
`email` = '%m'";

# This query has to return the subject of the autoresponder entry
identified by email %m
$conf['q_subject'] = "SELECT `subject` FROM `autoresponder` WHERE
`email` = '%m'";

######################################
# Logger class #
######################################

class Logger
{
var $logfile;
var $str;

function addLine($str)
{
$str = date("Y-m-d h:i:s")." ".$str;
$this->str .= "\n$str";
echo $str."\n";
}

function writeLog(&$conf)
{
if (! $conf['write_log'] ) return;

if (is_writable($conf['log_file_path']))
{
$this->addLine("--------- End execution ------------");
if (!$handle = fopen($conf['log_file_path'], 'a'))
{
echo "Cannot open file ({$conf['log_file_path']})";
exit;
}

if (fwrite($handle, $this->str) === FALSE)
{
echo "Cannot write to file)";
exit;
}
else
{
echo "Wrote log successfully.";
}

fclose($handle);

}
else
{
echo "Error: The log file is not writeable.\n";
echo "The log has not been written.\n";
}
}
}

######################################
# Create log object #
######################################
$log = new Logger();

######################################
# function endup() #
######################################
function endup(&$log, &$conf)
{
$log->writeLog($conf);
exit;
}

######################################
# Database connection #
######################################
$link = @mysql_connect($conf['mysql_host'], $conf['mysql_user'],
$conf['mysql_password']);
if (!$link)
{
$log->addLine("Could not connect to database. Abborting.");
endup($log, $conf);
}
else
{
$log->addLine("Connection to database established successfully");

if (!mysql_select_db($conf['mysql_database']))
{
$log->addLine("Could not select database ".$conf
['mysql_database']);
endup($log, $conf);
}
else
{
$log->addLine("Database selected successfully");
}
}

######################################
# Update database entries #
######################################
$result = mysql_query($conf['q_disable_forwarding']);

if (!$result)
{
$log->addLine("Error in query ".$conf
['q_disable_forwarding']."\n".mysql_error());
}
else
{
$log->addLine("Successfully updated database (disabled entries)");
}

mysql_query($conf['q_enable_forwarding']);

if (!$result)
{
$log->addLine("Error in query ".$conf
['q_enable_forwarding']."\n".mysql_error());
}
else
{
$log->addLine("Successfully updated database (enabled entries)");
}

######################################
# Catching dirs of autoresponders mailboxes #
######################################

// Corresponding email addresses
$result = mysql_query($conf['q_forwardings']);

if (!$result)
{
$log->addLine("Error in query ".$conf
['q_forwardings']."\n".mysql_error());
exit;
}

$num = mysql_num_rows($result);

for ($i = 0; $i < $num; $i++)
{
$emails[] = mysql_result($result, $i, "email");
$name[] = mysql_result($result, $i, "descname");
}

// Fetching directories
for ($i = 0; $i < $num; $i++)
{
$result = mysql_query(str_replace("%m", $emails[$i], $conf
['q_mailbox_path']));

if (!$result)
{
$log->addLine("Error in query ".$conf
['q_mailbox_path']."\n".mysql_error()); exit;
}
else
{
$log->addLine("Successfully fetched maildir directories");
}

$paths[] = mysql_result($result, 0, 'path') . 'new/';
}

######################################
# Reading new mails #
######################################
if ($num > 0)
{
$i = 0;

foreach ($paths as $path)
{
foreach(scandir($path) as $entry)
{
if ($entry != '.' && $entry != '..')
{
if (time() - filemtime($path . $entry) - $conf['cycle'] <= 0)
{
$mails[] = $path . $entry;

###################################
# Send response #
###################################

// Reading mail address
$mail = file($path.$entry);

foreach ($mail as $line)
{
$line = trim($line);

if (substr($line, 0, 5) == 'From:')
{
if ((strpos($line, '<') > 0) && (strpos($line, '>') > 0)) {
$address = substr($line, strpos($line, '<') + 1, strpos
($line, '>') - strpos($line, '<')-1)."\n";
} else {
$address= str_replace("From:","",$line);
}
break;
}
}

// Check: Is this mail allready answered

if (empty($address))
{
$log->addLine("Error, could not parse mail $path");
}
else
{
// Get data of current mail
$email = $emails[$i];

// Get subject
$result = mysql_query(str_replace("%m", $emails[$i], $conf
['q_subject']));

if (!$result)
{
$log->addLine("Error in query ".$conf
['q_subject']."\n".mysql_error()); exit;
}
else
{
$log->addLine("Successfully fetched subject of {$emails
[$i]}");
}

$subject = mysql_result($result, 0, 'subject');

// Get Message
$result = mysql_query(str_replace("%m", $emails[$i], $conf
['q_messages']));

if (!$result)
{
$log->addLine("Error in query ".$conf
['q_messages']."\n".mysql_error()); exit;
}
else
{
$log->addLine("Successfully fetched message of {$emails
[$i]}");
}

$message = mysql_result($result, 0, 'message');

$headers = "From: ".$name[$i]."<".$emails[$i].">";

// Check if mail is allready an answer:
if (strstr($mail, $message))
{
$log->addLine("Mail from {$emails[$i]} allready answered");
break;
}

// strip the line break from $address for checks
// fix by Karl Herrick, thank's a lot
if ( substr($address,0,strlen($address)-1) == $email )
{
$log->addLine("Email address from autoresponder table
is the same as the intended recipient! Not sending the mail!");
break;
}

mail($address, $subject, $message, $headers);
}
}
}
}

$i++;
}
}

$log->writeLog($conf);
echo "End execution.";
?>

rated-x

unread,
Jul 6, 2009, 9:09:15 PM7/6/09
to goldfish-user
thanks a lot it work :)

> ...
>
> read more »

Reply all
Reply to author
Forward
0 new messages