| // | | // +-----------------------------------------------------------------------+ ?> connect($host , $port ) )){ echo "ERROR: " . $ret->getMessage() . "\n"; exit(); } // Login using username/password. APOP will // be tried first if supported, then basic. if(PEAR::isError( $ret= $pop3->login($user , $pass,'USER' ) )){ echo "ERROR: " . $ret->getMessage() . "\n"; exit(); } echo "

getNumMsg

\n"; echo "
" . $pop3->numMsg() . "
\n"; if ($pop3->numMsg() < 1) { $pop3->disconnect(); exit(); } $a=$pop3->getListing(); echo "\n"; //print_r($a); //exit(); /* // read email using stdin $fd = fopen("php://stdin", "r"); $email = ""; while (!feof($fd)) { $email .= fread($fd, 1024); } fclose($fd); */ $params['include_bodies'] = true; $params['decode_bodies'] = true; $params['decode_headers'] = true; // possibly loop through all messages although we could just post them one at a time. // $pop3->getNumMsg; $message=new Mail_mimeDecode($pop3->getMsg(1)); $mailObj=$message->decode($params); // Who is it from $from=$mailObj->headers['from']; // Get Subject $subj=$mailObj->headers['subject']; // Get Date $date=$mailObj->headers['date']; // Get Message Body $body=$mailObj->parts[0]->body; //filter phone number out of subject line $subj = trim(preg_replace("/\[[A-Za-z0-9\+\s]*\]/", "", $subj)); //get rid of Vodafone blurp $body = preg_replace("/Hi,\syou[A-Za-z0-9\:\n\r\/\?,\.\s=\&\(\)]*/","",$body); $txtbody = $body; $htmlbody = $body; //connect to database mysql_connect($mysql_host,$mysql_user,$mysql_pass); @mysql_select_db($mysql_db) or die( "Unable to select database"); $newdate = chgFormatDate($date); $gather="From:$from\nDate:$newdate\nSubject:$subj\nBody:$body"; // Get and Save the Attachments foreach($mailObj->parts as $key=>$val): $tmpObj=$mailObj->parts[$key]; $tmp=$tmpObj->d_parameters['filename']; if(!empty($tmp)) { $fd = fopen($tmp, 'w'); fwrite($fd, $tmpObj->body); // close file fclose($fd); $query="SELECT MAX(id) FROM $txp_imageTable"; $result=mysql_query($query); // $num=mysql_numrows($result); $destfile = (mysql_result($result,0,"MAX(id)") + 1) . ".jpg"; $im_width = image_info($tmp, "width"); $im_height = image_info($tmp, "height"); //print_r("width: " . $im_width . " Height: " . $im_height); if ($im_width > $forcedwidth) { // load image with GD to to resize to desired size maintaining aspect ratio. resampimagejpg($forcedwidth, $forcedheight, $tmp, $txp_imagedir . $destfile, $imgcomp); $im_width = image_info($txp_imagedir . $destfile, "width"); $im_height = image_info($txp_imagedir . $destfile, "height"); } else { copy($tmp, $txp_imagedir . $destfile); } $query="INSERT INTO $txp_imageTable (name, ext, w, h, alt, caption, date, author, thumbnail) VALUES ('" . $tmp . "', '.jpg', " . $im_width . ", " . $im_height . ", '" . $tmp ." from mobile phone', '" . $tmp . " from mobile phone', '" . $newdate . "', '". $txp_author_id . "', 0 )"; print_r($query); $r1 = mysql_query( $query ) or die('Error, query failed. ' . mysql_error()); // Include image in post $txtbody = "!" . $txp_imageurl . $destfile . " (Picture from Mobile Phone)!\n\n" . $txtbody; $htmlbody = "

\"Picture

\n\n

" . $htmlbody . "

"; } endforeach; $query="SELECT MAX(id) FROM $txp_txpTable"; $result=mysql_query($query); $new_id = (mysql_result($result,0,"MAX(id)") + 1); $sql = "INSERT INTO textpattern (ID, Posted, AuthorID, LastMod, LastmodID, Title, Body, Body_html, Category2, Annotate, AnnotateInvite, Section, url_title, uid, feed_time) VALUES ($new_id, '" . $newdate . "', '" . $txp_author_id . "', '" . $newdate . "', '" . $txp_author_id . "', '" . mysql_real_escape_string($subj) . "', '" . mysql_real_escape_string($txtbody) . "', '" . mysql_real_escape_string($htmlbody) . "', " . "'', " . "1," . "'Comment', '" . $txp_section . "', '" . strtolower(preg_replace("/\s/" , "-" , $subj)) . "', '" . md5($newdate) . "', '" . $newdate . "')"; echo "

textpattern SQL

\n"; echo "
\n";
print_r($sql);
echo "
\n"; $r2 = mysql_query( $sql ) or die('Error, query failed. ' . mysql_error()); // if we inserted the blog completely then delete it from the server if (($r1) and ($r2)) { $pop3->deleteMsg(1); } mysql_close(); if (mail($to, $subject ." - " . $subj, $txtbody)) { echo("

Message successfully sent!

"); } else { echo("

Message delivery failed...

"); } // Get listing details of the maildrop echo "

getListing()

\n"; echo "
\n";
print_r($pop3->getListing());
echo "
\n"; // Get size of maildrop echo "

getSize()

\n"; echo "
" . $pop3->getSize() . "
\n"; //Delete the message we just entered on the blog //$pop3->deleteMsg(1); // Disconnect $pop3->disconnect(); function LoadJpeg($imgname) { $im = @imagecreatefromjpeg($imgname); /* Attempt to open */ if (!$im) { /* See if it failed */ $im = imagecreatetruecolor(150, 30); /* Create a black image */ $bgc = imagecolorallocate($im, 255, 255, 255); $tc = imagecolorallocate($im, 0, 0, 0); imagefilledrectangle($im, 0, 0, 150, 30, $bgc); /* Output an errmsg */ imagestring($im, 1, 5, 5, "Error loading $imgname", $tc); } return $im; } /** * mixed image_info( file $file [, string $out] ) * * Returns information about $file. * * If the second argument is supplied, a string representing that information will be returned. * * Valid values for the second argument are IMAGE_WIDTH, 'width', IMAGE_HEIGHT, 'height', IMAGE_TYPE, 'type', * IMAGE_ATTR, 'attr', IMAGE_BITS, 'bits', IMAGE_CHANNELS, 'channels', IMAGE_MIME, and 'mime'. * * If only the first argument is supplied an array containing all the information is returned, * which will look like the following: * * [width] => int (width), * [height] => int (height), * [type] => string (type), * [attr] => string (attributes formatted for IMG tags), * [bits] => int (bits), * [channels] => int (channels), * [mime] => string (mime-type) * * Returns false if $file is not a file, no arguments are supplied, $file is not an image, or otherwise fails. * **/ // These constants are used by image_info(), below. define ('IMAGE_WIDTH', 'width'); define ('IMAGE_HEIGHT', 'height'); define ('IMAGE_TYPE', 'type'); define ('IMAGE_ATTR', 'attr'); define ('IMAGE_BITS', 'bits'); define ('IMAGE_CHANNELS', 'channels'); define ('IMAGE_MIME', 'mime'); function image_info($file = null, $out = null) { // If $file is not supplied or is not a file, warn the user and return false. if (is_null($file) || !is_file($file)) { echo '

Warning: image_info() => first argument must be a file.

'; return false; } // Defines the keys we want instead of 0, 1, 2, 3, 'bits', 'channels', and 'mime'. $redefine_keys = array( 'width', 'height', 'type', 'attr', 'bits', 'channels', 'mime', ); // If $out is supplied, but is not a valid key, nullify it. if (!is_null($out) && !in_array($out, $redefine_keys)) $out = null; // Assign usefull values for the third index. $types = array( 1 => 'GIF', 2 => 'JPG', 3 => 'PNG', 4 => 'SWF', 5 => 'PSD', 6 => 'BMP', 7 => 'TIFF(intel byte order)', 8 => 'TIFF(motorola byte order)', 9 => 'JPC', 10 => 'JP2', 11 => 'JPX', 12 => 'JB2', 13 => 'SWC', 14 => 'IFF', 15 => 'WBMP', 16 => 'XBM' ); $temp = array(); $data = array(); // Get the image info using getimagesize(). // If $temp fails to populate, warn the user and return false. if (!$temp = getimagesize($file)) { echo '

Warning: image_info() => first argument must be an image.

'; return false; } // Get the values returned by getimagesize() $temp = array_values($temp); // Make an array using values from $redefine_keys as keys and values from $temp as values. foreach ($temp AS $k => $v) { $data[$redefine_keys[$k]] = $v; } // Make 'type' usefull. $data['type'] = $types[$data['type']]; // Return the desired information. return !is_null($out) ? $data[$out] : $data; } /******************************************************************************* * Here's a funtion i used to resize and save images uploaded by the user, you can either create thumbnails or other images. * Main "feature" is that the width and height stay relativ to each other. * * imgcomp is the quality, i turned it around so now its from 0 -best to 100 -most compressed. * * For gif version just change the functions names. ********************************************************************************/ function resampimagejpg($forcedwidth, $forcedheight, $sourcefile, $destfile, $imgcomp) { $g_imgcomp=100-$imgcomp; $g_srcfile=$sourcefile; $g_dstfile=$destfile; $g_fw=$forcedwidth; $g_fh=$forcedheight; if(file_exists($g_srcfile)) { $g_is=getimagesize($g_srcfile); if(($g_is[0]-$g_fw)>=($g_is[1]-$g_fh)) { $g_iw=$g_fw; $g_ih=($g_fw/$g_is[0])*$g_is[1]; } else { $g_ih=$g_fh; $g_iw=($g_ih/$g_is[1])*$g_is[0]; } $img_src=imagecreatefromjpeg($g_srcfile); $img_dst=imagecreate($g_iw,$g_ih); imagecopyresampled($img_dst, $img_src, 0, 0, 0, 0, $g_iw, $g_ih, $g_is[0], $g_is[1]); imagejpeg($img_dst, $g_dstfile, $g_imgcomp); imagedestroy($img_dst); return true; } else return false; } function chgFormatDate($date){ $timestamp = strtotime($date); $date = date('Y-m-d H:i:s', $timestamp); return $date; }