<?php require('template.hack');
require_once('Mail.php');
require_once('Mail/mime.php');
/*
mailcky.hack---sends mail to me.
Chris K. Young <cky@pobox.com>, March 2004.
$Id: mailcky.hack,v 1.3 2004/03/29 14:00:39 cky Exp $
Copyright (c) 2004 Chris K. Young. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public Licence as published by
the Free Software Foundation; either version 2 of the Licence, or (at
your option) 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 Licence for more details.
You should have received a copy of the GNU General Public Licence
along with this program; if not, write to Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*/
class mailcky {
var $tmpl;
function print_header() {
$this->tmpl = new template('The mailcky gimmick');
$this->tmpl->set_rcsid('$Id: mailcky.hack,v 1.3 2004/03/29 14:00:39 cky Exp $');
$this->tmpl->print_header();
}
function validate_input() {
switch ($_SERVER['REMOTE_ADDR']) {
case '65.248.4.183':
case '210.55.69.57':
case '203.167.190.199':
return isset($_FILES['file'])
&& is_uploaded_file($_FILES['file']['tmp_name']);
default:
return false;
}
}
function process_input() {
$mime = new Mail_mime("\n");
$mime->setTxtBody($_POST['text']);
$file = $_FILES['file'];
$mime->addAttachment($file['tmp_name'], $file['type'], $file['name'],
true);
$body = $mime->get();
$header = $mime->headers(array('Subject' => "Message from {$_SERVER['REMOTE_ADDR']}"));
$mailer = Mail::factory('mail');
if ($mailer->send('cky@spillville.com', $header, $body)) {
?>
<p>Yay, your message has successfully been sent to the author.</p>
<?php
} else {
?>
<p>Whoops, your message hasn't successfully been sent to the author.</p>
<?php
}
}
function print_form() {
?>
<p>The <samp>mailcky</samp> gimmick sends an email to the author, with an attachment. For security reasons, only selected IP addresses can use this.</p>
<form action="<?php print($_SERVER['PHP_SELF']); ?>" method="post" enctype="multipart/form-data">
<p><label for="text" accesskey="m">Message:</label><br /><textarea id="text" name="text" rows="8" cols="64"></textarea></p>
<p><label for="file" accesskey="f">File:</label> <input id="file" type="file" name="file" /></p>
<p><input type="submit" value="Send message" accesskey="s" /></p>
</form>
<?php
}
function print_footer() {
$this->tmpl->print_footer();
}
}
?>