Auto responder for Imp
rob.thomson
rob.thomson@biggroup.co.uk
Fri, 10 Nov 2000 10:51:02 +0000
Hi All,
Thought you might like this little snippet of code we have added to our
IMP mail system.
Essentially, it uses th PHP FTP functions to allow updates to the
".procmailrc" file on your mail server. By updating the procmail, the
facility is avaliable to provide out of office messages via the web interface.
This code is stable & working perfectly on our system, however is
currently lacking in any true IMP intergration. -> Thats where the fun
starts -> Our development team does not have the time or resources to
extend this much further, do should anyone else like to take up the challenge....?
Thanks
Rob Thomson
Manager
Big Interactive
=========================
Code Follows below
=========================
<?
#######################################
#
# Biggroup Autoresponder v0.1a
# ----------------------------
#
# Developed by Dave Shanley,
# For Big Interactive, Part of Internal
# Intranet.
#
# Hacked for IMP. http://www.horde.org
#
#######################################
require '../lib/horde.lib';
require './lib/imp.lib'; /* IMPlib is the IMP function library
*/
require './config/defaults.php3'; /* Defaults configuration file */
require '../config/horde.php3';
require './config/html.php3';
require './config/lang.php3';
$language = select_lang();
require './lib/postconf.php3';
require "./locale/$language/folders.lang";
require './locale/local/folders.lang';
$help_file = 'folders.help';
require "./locale/defines/$help_file";
error_reporting($default->error_level); /* set error level from imp.lib
*/
/* retrieve authentication information from session */
page_open(array('sess' => 'HordeSession'));
page_close();
if (!isset($imp) || !is_object($imp)) { header('Location: ' .
$sess->url('login.php3?reason=logout')); exit; }
$imp->unpickle();
$imp->authenticate(OP_HALFOPEN);
$stamp = date("mdy");
// start naughty words array
$swear[0] = "fuck"; $swear[1] = "shit";
$swear[2] = "piss"; $swear[3] = "wank";
$swear[4] = "cunt"; $swear[5] = "fucker";
$swear[6] = "fucking"; $swear[7] = "fucking hell";
$swear[8] = "fucked"; $swear[9] = "wanker";
$swear[10] = "asshole"; $swear[11] = "bitch";
$swear[12] = "whore"; $swear[13] = "motherfucker";
$swear[14] = "queer"; $swear[15] = "bastard";
$imapuser = $imp->user ;
$pass = $imp->pass ;
$ftpserver = "fileserver.biggroup.co.uk";
$responderData = "/tmp/$imapuser.responder";
$procmailData = "/tmp/$imapuser.procmailrc";
$versionNum = "0.2b";
$procmail = "
VERBOSE=off\n
SENDMAIL=/usr/lib/sendmail\n
PMDIR=$HOME/.procmail\n\n
:0 ic
* ^TO$imapuser@biggroup.co.uk
*!^FROM_DAEMON
*!^X-Loop: $imapuser@biggroup.co.uk
|(formail -r -A \"Precedence: $imapuser\" \
-I\"From: $imapuser <$imapuser@biggroup.co.uk>\" \
-I\"Subject: Out of Office Reply\" \
-A \"X-Loop: $imapuser@biggroup.co.uk\"; \
cat /home/$imapuser/.autoresponder )|/usr/lib/sendmail -t";
function errorMsg($msg) {
?>
<table width="100%" cellspacing="0" cellpadding="5">
<tr align="right">
<td><img src="error.gif" width="129" height="39"></td>
</tr>
<tr bgcolor="#990000">
<td>
<p><font face="Verdana, Helvetica, Arial" size="2"
color="#FFFFFF">There
is a problem. The reported error is: <b><? echo $msg ?></b></font></p>
<p><font face="Verdana, Helvetica, Arial" size="2"
color="#FFFFFF">Please
contact <b>Dave Shanley</b> (ext 261) and report this problem to him.</font></p>
</td>
</tr>
</table>
</td>
</tr>
</table>
</form>
</body>
</html>
<?
}
// start nosubmit (default entry page)
function placeFooter() {
global $imapuser, $pass, $ftpserver, $responderData, $procmailData,
$versionNum, $procmail, $swear;
$conn_id = @ftp_connect($ftpserver);
$login_result = @ftp_login($conn_id,
"$imapuser", "$pass");
// check connection
if ((!$conn_id) || (!$login_result)) {
errorMsg("Unable to FTP into fileserver.");
exit;
}
// check download status
if (!$get = @ftp_get($conn_id,
"$procmailData", "/home/$imapuser/.procmailrc", FTP_ASCII)) {
$enabled = "0";
} else {
$enabled = "1";
if (!$getmessage =
@ftp_get($conn_id, "$responderData", "/home/$imapuser/.autoresponder",
FTP_ASCII)) {
errorMsg("Unable to ftp_get .autoresponder data");
exit;
}
}
// close the FTP stream
@ftp_quit($conn_id);
?>
<p><font face="Verdana, Helvetica, Arial"
size="1">This module is to enable you to set up your <b>out of office
reply, </b>to email sent to your mailbox. Simply type the text
you want
to appear in the email sent back to the sender of any mail
delivered to
your mailbox.</font></p>
</td>
</tr>
<tr>
<td valign="top" align="right"><font face="Verdana, Helvetica,
Arial" size="1"><b>Body
of message:</b></font></td> <td align="left" valign="top">
<textarea name="body" cols="60" rows="8"><? if($fe =
@fopen("$responderData","r")){ fpassthru($fe); } else { print "error,
unable to open file"; } ?></textarea>
</td></tr><tr><td> </td>
<td> <font face="Verdana, Helvetica, Arial" size="1">Your
Autoresponder is currently : <?
if($enabled == 1){
echo "<b>ENABLED</b> <input type=\"checkbox\"
name=\"disable\"><b>Disable?</B>";
} elseif($enabled == 0) {
echo "<b>DISABLED</b> <input type=\"checkbox\"
name=\"enable\"><b>Enable?</B>";
} ?></font><BR><BR>
<font face="Verdana, Helvetica, Arial" size="1">(please press only <B>once</b>)</font><br>
<input type="submit" name="responderSubmit" value="Update My Autoresponder"><BR><BR>
<font face="Verdana, Helvetica, Arial" size="1"><B>- Big
Autoresponder v<? echo $versionNum ?>.</B> By <A
HREF="mailto:dave.shanley@biggroup.co.uk">Dave Shanley</a> (codeMonkey)</font>
</td>
</tr>
</table>
</form>
</body>
</html>
<?
}
if(!isset($responderSubmit)) {
?>
<html>
<head>
<title>Autoresponder</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF">
<form action="<? echo $PHP_SELF ?>" method="post">
<table width="70%" border="0" cellspacing="0" cellpadding="8">
<tr>
<td colspan="2"><img src="logo.gif" width="304" height="39"></td>
</tr>
<tr>
<td colspan="2">
<?
placeFooter();
}
// start submit (form processing)
if(isset($responderSubmit)) {
?>
<html>
<head>
<title>Autoresponder</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF">
<form action="<? echo $PHP_SELF ?>" method="post">
<table width="70%" border="0" cellspacing="0" cellpadding="8">
<tr>
<td colspan="2"><img src="logo.gif" width="304" height="39"></td>
</tr>
<tr>
<td colspan="2">
<? $i = 0;
while($i < count($swear)){
if(ereg($swear[$i], $body)) {
?> <table width="100%" cellspacing="0" cellpadding="5">
<tr align="right">
<td><img src="swearing.gif" width="209" height="31"></td>
</tr>
<tr bgcolor="#006666">
<td>
<p><font face="Verdana, Helvetica, Arial" size="2"
color="#FFFFFF">Excuse
me!, </font></p>
<p><font face="Verdana, Helvetica, Arial" size="2"
color="#FFFFFF">No Swearing
allowed, If you want to swear, then come up to Big I and
swear at Marc
beltrante. He likes having people swear at him.</font></p>
</td>
</tr>
</table>
<? placeFooter(); ?>
</td>
</tr>
</table>
</body>
</html>
<?
exit;
}
$i++;
}
// open data file for amending
if(!$fd = fopen("$responderData","w+")) {
errorMsg("Unable to open user.responder file from /tmp");
exit;
}
$myMessage = "$body";
@fputs($fd, "$myMessage");
@fclose($fd);
$conn_id = @ftp_connect($ftpserver);
$login_result = @ftp_login($conn_id, $imapuser, $pass);
// check connection
if ((!$conn_id) || (!$login_result)) {
errorMsg("Unable to FTP into fileserver.");
exit;
} // upload autoresponder file
$responderupload = ftp_put($conn_id,
".autoresponder", "$responderData", FTP_ASCII);
// start enable/disable/uploads
if(isset($enable)) {
//create .procmailrc file
// open data file for amending
if(!$fp = fopen("$procmailData","w+")) {
errorMsg("Unable to open user.procmail file from /tmp");
exit;
} else {
@fputs($fp, "$procmail");
@fclose($fp);
$procupload = ftp_put($conn_id, ".procmailrc",
"$procmailData", FTP_ASCII);
if(!$procupload) { // check upload status
errorMsg("Unable to FTP
user.procmailrc to fileserver");
exit;
} else { // return
?>
<table width="100%"
cellspacing="0" cellpadding="5">
<tr align="right">
<td><img src="success.gif" width="158" height="37"></td>
</tr>
<tr bgcolor="#000066">
<td>
<p><font face="Verdana, Helvetica, Arial" size="2"
color="#FFFFFF">Your
Autoresponder as been <b>ENABLED</b> and your out of
office reply has
been set. Until you disable your autoresponder
people who email you will
get an automatic reply back with your out of office reply.<br>
<br>
To <b>disable</b> your autoresponder, simply click on
the icon on the
left hand side menu.</font></p>
<p><font face="Verdana, Helvetica, Arial" size="2"
color="#FFFFFF">- Dave
Shanley (Senior Developer, Big Interactive)</font> </p>
</td>
</tr>
</table>
<? placeFooter(); ?>
</td>
</tr>
</table>
</body>
</html>
<?
exit;
} // end of procupload ifstatement
} // end of unable to open file if
}// end if enable ifstatement
if(isset($disable)) { // diasble .procmailrc
$procdisable = @ftp_rename($conn_id, ".procmailrc", ".procmailrc.disable");
// return success message
?>
<table width="100%"
cellspacing="0" cellpadding="5">
<tr align="right">
<td><img src="success.gif" width="158" height="37"></td>
</tr>
<tr bgcolor="#000066">
<td>
<p><font face="Verdana, Helvetica, Arial" size="2"
color="#FFFFFF">Your
Autoresponder as been <b>DISABLED</b>. Until you
re-enable your autoresponder people who email you will
NOT get an
automatic reply back with your out of office reply.<br>
<br>
To <b>enable</b>
your autoresponder, select the disable checkbox</font></p>
<p><font face="Verdana, Helvetica, Arial" size="2"
color="#FFFFFF">- Dave
Shanley (Senior
Developer, Big Interactive)</font> </p>
</td>
</tr>
</table>
<? placeFooter(); ?></td>
</tr>
</table>
</body>
</html>
<?
exit;
} // end if disable ifstatement
if(!isset($disable) && !isset($enable)) { // default message
// return success message
?>
<table width="100%"
cellspacing="0" cellpadding="5">
<tr align="right">
<td><img src="success.gif" width="158" height="37"></td>
</tr>
<tr bgcolor="#000066">
<td>
<p><font face="Verdana, Helvetica, Arial" size="2"
color="#FFFFFF">Your
Autoresponder Message has been updated.</p>
<p><font face="Verdana, Helvetica, Arial" size="2"
color="#FFFFFF">- Dave
Shanley (Senior Developer, Big Interactive)</font> </p>
</td>
</tr>
</table>
<? placeFooter(); ?></td>
</tr>
</table>
</body>
</html>
<?
exit;
} // end if disable ifstatement
@ftp_quit($conn_id);
exit;
} // end