for deleted mail to something that works on Blackberries // // v0.2, Mar 14 04 // - fixed bug where mailbox has less than 14 pieces of mail // - fixed bug where mail showed up even when deleted // - added 'type=password' to the password field // - added 'You have no mail' when you, er, have no mail // // http://james.cridland.net/code // // You're free to use this, but please keep this URL intact //////////////////////////////////////////////////// //////////////////////////////////////////////////// // Tiddly configs: // This site - for setting the cookie. // Example: "www.yahoo.com"; $site = "www.yahoo.com"; // Where will this script run? // You need to include this here. // Example "/mail/" $where = "/mail/"; // Advanced configuration. You don't need to fiddle unless you want to. $heightofpage = "8"; $widthofpage = "45"; // These are the defaults for the height and width of the page. Users // can still change them should they wish. // That's all the config you need //////////////////////////////////////////////////// //Compress this page ob_start( 'ob_gzhandler' ); //Set no caching header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); header("Cache-Control: no-store, no-cache, must-revalidate"); header("Cache-Control: post-check=0, pre-check=0", false); header("Pragma: no-cache"); //Add correct encoding charset to enable validation //header ("Content-Type: text/html; charset=ISO-8859-1"); if ($action==setcookie) { //Set the cookie setcookie("mailusername",$setmailusername,time()+60*60*24*365,$where,$site); setcookie("mailpassword",$setmailpassword,time()+60*60*24*365,$where,$site); setcookie("mailemail",$setmailemail,time()+60*60*24*365,$where,$site); setcookie("mailname",$setmailname,time()+60*60*24*365,$where,$site); setcookie("mailserver",$setmailserver,time()+60*60*24*365,$where,$site); setcookie("widthofpage",$setwidthofpage,time()+60*60*24*365,$where,$site); setcookie("heightofpage",$setheightofpage,time()+60*60*24*365,$where,$site); //...and also set the variables as if they've been set by the cookie $mailusername=$setmailusername; $mailpassword=$setmailpassword; $mailemail=$setmailemail; $mailname=$setmailname; $mailserver=$setmailserver; $widthofpage=$setwidthofpage; $heightofpage=$setheightofpage; $action="list"; } if ($action==logout) { //Log out only deletes the mail password cookie setcookie("mailpassword",'',time()-1000,$where,$site); $action="loggedout"; } if ($action==fulllogout) { //Full logout deletes everything setcookie("mailusername",'',time()-1000,$where,$site); setcookie("mailpassword",'',time()-1000,$where,$site); setcookie("mailemail",'',time()-1000,$where,$site); setcookie("mailname",'',time()-1000,$where,$site); setcookie("mailserver",'',time()-1000,$where,$site); setcookie("widthofpage",'',time()-1000,$where,$site); setcookie("heightofpage",'',time()-1000,$where,$site); $action="fullloggedout"; } //Start the HTML page echo "Blackberry e-mail"; //And now check for the actions. if ($action=="privacy") { echo "

Privacy info


This service does not use any databases, and does not store your information in any way.

All login information is stored in a cookie on your own machine, and not stored on this server.

All activity with this server is not sent securely. You use this at your own risk.

Log in

"; die; } if ($action=="loggedout") { echo "

Logged out.


All your details except your password still live in a cookie on your Blackberry, for ease of logging in next time. To delete them all, click this.

Have a good day!

Log in

"; die; } if ($action=="fullloggedout") { echo "

Full log-out.


All your details are now removed.

As a further precaution, you can delete all cookies on your Blackberry - click the thumbwheel, choose 'Options', then 'General Properties', then click the thumbwheel again to choose 'Delete cookie cache'.

Have a good day!

Log in

"; die; } if (!isset($mailpassword)) { // If your password is not set, then the system should ask you to log on. if (!isset($widthofpage)) {$widthofpage = "45";} if (!isset($heightofpage)) {$heightofpage = "8";} echo "
Log on | privacy
IMAP mailserver:
Username:
Password:
Display email:
Display name:

Optional configuration: Screen width:
Screen height:
To change optional configuration, log out again.
"; die; } // Connect to the mailbox. $mbox = @imap_open ("{".$mailserver.":143}INBOX", $mailusername, $mailpassword) or die("I cannot connect.

Log out to try connecting again."); if (!isset($action)) {$action="list";} if (isset($read)) {$action="read";} if (isset($delete)) {$action="delete";} if (isset($send)) {$action="send";} if ($action=="send") { //Sending a piece of mail if ($send>0) { $header = imap_headerinfo($mbox, $send, 32, 32); $from = $header->from; foreach ($from as $id => $object) { $fromname = $object->personal; $fromaddress = $object->mailbox . "@" . $object->host; if (strlen($fromname)<2) { $fromname = substr($fromaddress,0,strpos($fromaddress,'@')); } } $subject = "Re: ".decode_iso88591($header->subject); } echo "
"; echo "To:
Email:
"; echo "Subject:
"; if ($send>0) { $body = imap_body($mbox, $send); } echo ""; echo ""; echo ""; echo "
"; } if ($action=="send2") { // Do the send. mail("$toname <$email>", "$subject", stripslashes($message), "From: $mailname <$mailemail>\r\n" . "X-Mailer: jrc/Blackberry http://james.cridland.net/code/\r\n"); $action="list"; } if ($action=="delete") { //Mark a piece of e-mail for deletion imap_delete($mbox, $delete); $action='expunge'; } if ($action=="expunge") { //Delete all e-mail marked for deletion imap_expunge($mbox); $action='list'; } if ($action=="read") { $header = imap_headerinfo($mbox, $read, 32, 32); $from = $header->from; foreach ($from as $id => $object) { $fromname = $object->personal; $fromaddress = $object->mailbox . "@" . $object->host; if (strlen($fromname)<2) { $fromname = substr($fromaddress,0,strpos($fromaddress,'@')); } } $subject = decode_iso88591($header->subject); $tools="delete | reply | index"; if (!isset($html)) { if (strlen(get_part($mbox, $read, "TEXT/HTML"))>1) {$tools=$tools." | HTML"; } } else { if (strlen(get_part($mbox, $read, "TEXT/PLAIN"))>1) {$tools=$tools." | text"; } } echo "$fromname
$subject
$tools

"; if (!isset($html)) { $body = get_part($mbox, $read, "TEXT/PLAIN"); //Make this look nice and spot any links $body = ereg_replace("\n","
",$body); $body = preg_replace("/([^\w\/])(www\.[a-z0-9\-]+\.[a-z0-9\-]+)/i","$1http://$2", $body); $body = preg_replace("/([\w]+:\/\/[\w-?&;#~=\.\/\@]+[\w\/])/i","$1", $body); $body = preg_replace("/([\w-?&;#~=\.\/]+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?))/i","$1",$body); if (strlen($body)<1) {$body="There is no plaintext version of this mail.";} } else { $body = get_part($mbox, $read, "TEXT/HTML"); } echo $body; echo "
$tools"; } if ($action=="list") { //List all the e-mails. $status=imap_status($mbox,"{imap.spamcop.net:143}INBOX", SA_ALL); echo $status->unseen."/".$status->messages." | new | refresh"; if (!isset($start)) {$start = imap_num_msg($mbox);} $end = ($start-$heightofpage); if ($end<0) {$end=0;} else {echo " | more";} $note=""; if ($start=="0") {$note = "You have no mail.";} echo "
"; for ($i = $start; $i > $end; $i--) { $header = imap_headerinfo($mbox, $i, 32, 32); $from = $header->from; foreach ($from as $id => $object) { $fromname = $object->personal; $fromaddress = $object->mailbox . "@" . $object->host; if (strlen($fromname)<2) { $fromname = substr($fromaddress,0,strpos($fromaddress,'@')); } } $subject = decode_iso88591($header->subject); $text="$fromname: $subject"; if ($header->Unseen == "U" || $header->Recent == "N") { echo ""; if (strlen($text)>$widthofpage-5) {$text=substr($text,0,($widthofpage-7))."...";} } else { if ($header->Deleted == "D") { echo "[D]"; $note="[D] - Deleted messages will be expunged if you delete further messages. Expunge now";} if (strlen($text)>$widthofpage) {$text=substr($text,0,$widthofpage-2)."...";} } echo "$text"; if ($header->Unseen == "U" || $header->Recent == "N") { echo ""; } echo "
"; flush(); } echo $note; echo "
".substr($mailemail,0,strpos($mailemail,"@")).": logout"; } //Whatever we've been doing, close the mailbox. imap_close($mbox); //End the HTML page echo ""; //internal functions follow //To decode MIME headers - from www.php.net function decode_iso88591($string){ if ( strpos(strtolower($string), '=?iso-8859-1')===false ) return $string; $string=explode('?', $string); return strtolower($string[2]) == 'q' ?quoted_printable_decode($string[3]):base64_decode($string[3]); } //To decode MIME parts - from http://www.linuxscope.net/articles/mailAttachmentsPHP.html function get_mime_type(&$structure) { $primary_mime_type = array("TEXT", "MULTIPART","MESSAGE", "APPLICATION", "AUDIO","IMAGE", "VIDEO", "OTHER"); if($structure->subtype) { return $primary_mime_type[(int) $structure->type] . '/' .$structure->subtype; } return "TEXT/PLAIN"; } function get_part($stream, $msg_number, $mime_type, $structure = false,$part_number = false) { if(!$structure) { $structure = imap_fetchstructure($stream, $msg_number); } if($structure) { if($mime_type == get_mime_type($structure)) { if(!$part_number) { $part_number = "1"; } $text = imap_fetchbody($stream, $msg_number, $part_number); if($structure->encoding == 3) { return imap_base64($text); } else if($structure->encoding == 4) { return imap_qprint($text); } else { return $text; } } if($structure->type == 1) /* multipart */ { while(list($index, $sub_structure) = each($structure->parts)) { if($part_number) { $prefix = $part_number . '.'; } $data = get_part($stream, $msg_number, $mime_type, $sub_structure,$prefix . ($index + 1)); if($data) { return $data; } } // END OF WHILE } // END OF MULTIPART } // END OF STRUTURE return false; } // END OF FUNCTION ?>