$postVar ) { if( get_magic_quotes_gpc() ) { $_POST[$postIndex] = stripslashes($postVar); } $_POST[$postIndex] = utf8_encode($_POST[$postIndex]); } require_once 'Zend/Filter.php'; require_once 'Zend/Filter/StripTags.php'; require_once 'Zend/Filter/StringTrim.php'; $filters = new Zend_Filter(); $filters->addFilter(new Zend_Filter_StripTags()) ->addFilter(new Zend_Filter_StringTrim()); $pageTitle = array_key_exists('pageTitle', $_POST) ? $filters->filter($_POST['pageTitle']) : ''; $pageUrl = array_key_exists('pageUrl', $_POST) ? $filters->filter($_POST['pageUrl']) : ''; $bodyContent = array_key_exists('bodyContent', $_POST) ? $_POST['bodyContent'] : ''; $page = 'form'; $errors = array(); $bodyContent = ' Readability
' . $bodyContent . '
'; if('post' == strtolower($_SERVER['REQUEST_METHOD']) && isset($_POST['deliveryMethod'])) { // someone sent over an invalid if(!Readability::hasValidParams()) { Readability::logMessage("ERROR:Someone tried to send a request with an invalid set of parameters."); die(); } require_once 'Zend/Validate/EmailAddress.php'; //FILTER DATA $bodyContent = $_POST['bodyContent']; $deliveryMethod = $filters->filter($_POST['deliveryMethod']); $username = $filters->filter($_POST['username']); $key = $filters->filter($_POST['key']); $pageUrl = $filters->filter($_POST['pageUrl']); $pageTitle = $filters->filter($_POST['pageTitle']); if(!Readability::validateSecureKey($key)) { $errors[] = 'key'; Readability::logMessage("ERROR:Someone tried to send an email with an invalid key."); } // VALIDATE DATA $emailValidator = new Zend_Validate_EmailAddress(); // NO ERRORS SEND EMAIL if(count($errors) == 0) { // store the from address so it's saved for future use setcookie("username", $username, time()+3600*24*7*4, "/"); setcookie("deliveryMethod", $deliveryMethod, time()+3600*24*7*4, "/"); require_once 'Zend/Mail.php'; require_once 'Zend/Mail/Transport/Smtp.php'; $mailer = new Zend_Mail_Transport_Smtp('smtp.googlemail.com', Array( 'auth' => 'login', 'username' => 'readability@arc90.com', 'password' => '**********', 'ssl' => 'ssl', 'port' => 465, )); $mailer->EOL = "\r\n"; // gmail is fussy about this Zend_Mail::setDefaultTransport($mailer); $mail = new Zend_Mail(); $mail->setBodyText("This is a document sent by Readability from Arc90 to your Kindle."); $mail->setFrom('readability@arc90.com', 'Readability'); $mail->addHeader('Reply-To', 'readability@arc90.com'); $at = $mail->createAttachment($bodyContent); // $at->type = 'text/html'; $at->type = 'text/html; charset=UTF-8; name="readability.htm"'; $at->filename = ($pageTitle != "" ? $pageTitle : 'readability') . '.htm'; if($deliveryMethod == "wireless") { $mail->addTo('chrisd@arc90.com'); $mail->addTo($username . "@kindle.com"); } else { $mail->addTo($username . "@free.kindle.com"); } $mail->setSubject("Sent via Readability: {$pageTitle}"); try { if(!$mail->send()) { Readability::logMessage("ERROR:There was an error sending to kindle. POST: " . print_r($_POST, true)); } else { $page = 'complete'; } } catch(Exception $e) { Readability::logMessage("ERROR:There was an exception sending the email. POST: " . print_r($_POST, true)); Readability::logMessage("ERROR:".$e->getMessage()); } //header('location: close.html'); } } // end of: if method == POST elseif('get' == strtolower($_SERVER['REQUEST_METHOD'])) { $_SESSION['secureKey'] = Readability::generateSecureKey(); } class Readability { public static function isError($field, $errors) { if(in_array($field, $errors)) { return TRUE; } return FALSE; } public static function getErrorClass($field, $errors) { if(in_array($field, $errors)) { return 'class = "error"'; } return ''; } public static function getParam($param) { if(isset($_POST) && array_key_exists($param, $_POST)) { return $_POST[$param]; } elseif(isset($_COOKIE) && array_key_exists($param, $_COOKIE)) { return $_COOKIE[$param]; } return ''; } public static function logMessage($message) { echo $message; $logFile = dirname(__FILE__) . '/log.txt'; $handle = @fopen($logFile, 'a'); if(is_resource($handle)) { $message = date('Y-m-d G:i:s') . ' :: ' . $message . "\n"; fwrite($handle, $message); fclose($handle); } } public static function generateSecureKey($length = 8) { $sucureKey = ""; $possible = "012*3456)789b(cdfg#hjkmn@pqrs!tvwx[yz"; for($x=0; $x < $length; $x++) { $char = substr($possible, mt_rand(0, strlen($possible)-1), 1); if (!strstr($sucureKey, $char)) { $sucureKey .= $char; } } return $sucureKey; } /** * this adds a small (very small) level of security * * @param string $testKey * @return void * @author David Hauenstein */ public static function validateSecureKey($testKey) { if(!array_key_exists('secureKey', $_SESSION)) { $_SESSION['secureKey'] = self::generateSecureKey(); return false; } else { if($testKey != $_SESSION['secureKey']) { return false; } } return true; } public static function emailAsLinks($addresses) { $toReturn = ''; foreach($addresses as $address) { $toReturn .= '' . $address . ', '; } return substr($toReturn, 0, strlen($toReturn)-2); } public static function hasValidParams() { $requiredParams = array('bodyContent', 'deliveryMethod', 'username', 'key', 'pageTitle', 'pageUrl'); $sentParams = array_keys($_POST); foreach($requiredParams as $required) { if(!in_array($required, $sentParams)) { return false; } } return true; } } ?> xml version="1.0" encoding="utf-8" ?> Readability

Send to Kindle

Readability will deliver this document to your Kindle so you may read it at your leisure.

How shall we deliver your document?

Please enter your Amazon Kindle username.

@kindle.com
Please ensure readability@arc90.com is approved to send email to your kindle address. You can manage approved emails here.

A link to this page has been sent to

Thanks for using Readability.

Readability