Source of “mailcheck.php”.
115 lines, 3.1 KBytes.   Last modified 4:45 pm, 25th March 2014 PDT.
1 <?php // Emacs settings: -*- mode: Fundamental; tab-width: 4; -*- 2 3 //////////////////////////////////////////////////////////////////////////// 4 // // 5 // Pachylet: Andrew's Web Mail Interface // 6 // // 7 // Copyright (c) 2002-2014 // 8 // // 9 // See http://birrell.org/pachylet/help.php // 10 // // 11 // Displays or returns the count of a user's unread messages. // 12 // // 13 //////////////////////////////////////////////////////////////////////////// 14 15 require("pachysql.php"); // only for C_partsDir 16 17 $mode = (isset($_GET["mode"]) ? $_GET["mode"] : 'W'); 18 if (isset($_GET["n"])) { 19 // for debugging 20 $user = "test"; 21 $count = 0 + $_GET["n"]; 22 } else { 23 if (!isset($_GET["user"])) die("Requires a \"user\" parameter"); 24 $user = $_GET["user"]; 25 $fName = C_partsDir . "/$user/msgcount"; 26 $count = file_get_contents($fName); 27 if ($count === false) $count = 0; 28 $count += 0; 29 } 30 31 header("Expires: Sat, 1 Jan 2000 00:00:01 GMT"); 32 header("Cache-Control: no-store, no-cache, " . 33 "must-revalidate, proxy-revalidate"); 34 35 // 36 // Returning an image, constructed to show the message count 37 // 38 39 if ($mode == 'I' || $mode == 'i') { 40 if ($count === 0) { 41 header("Content-type: image/gif"); 42 passthru("convert noMail.gif -resize 40x16\! gif:-"); 43 } else { 44 header("Content-type: image/png"); 45 passthru("convert " . 46 // We build the graphic at 4x scale, to allow fine-grain 47 // positioning and sizing. It also seems to help with scaling 48 // and unsharp, perhaps because the "-resize" filter is better. 49 "-size 160x64 -depth 24 xc:transparent " . 50 "-fill '#6699cc' -draw 'arc 100,4 155,59 0,360' " . 51 "-fill white -background transparent -pointsize 48 " . 52 "-font Helvetica-Narrow-Bold -size 160x64 -gravity center " . 53 "label:" . ($count>99 ? "..." : escapeshellarg($count)) . " " . 54 "-geometry +48" . ($count>99 ? "-8" : "+5") . " -composite " . 55 "-resize 40x16 -unsharp 1.5x1.5+1.0+0.10 " . 56 "hasMail.gif -gravity northwest -composite " . 57 "png:-"); 58 } 59 60 61 // 62 // Returning an image, without the message count 63 // 64 } else if ($mode == "E" || $mode == "e") { 65 header("Content-type: image/gif"); 66 readfile($count > 0 ? "hasMail.gif" : "noMail.gif"); 67 68 69 // 70 // Returning a plain-text integer 71 // 72 73 } else if ($mode == 'N' || $mode == 'n') { 74 header("Content-type: text/plain"); 75 echo $count; 76 77 78 // 79 // Returning a web page 80 // 81 82 } else if ($mode == 'W' || $mode == 'w') { 83 ?> 84 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" 85 "http://www.w3.org/TR/html4/strict.dtd"> 86 <html> 87 <head> 88 <title>New mail poll for <?php echo htmlspecialchars($user) ?></title> 89 <link href="pachyletV2.css" rel=stylesheet> 90 </head> 91 <body> 92 <div class=dlogScreen> 93 <div id=login style="text-align: center"> 94 <?php echo "User &ldquo;" . htmlspecialchars($user) . "&rdquo; has " . 95 ($count==0 ? "no" : $count) . " unread message" . 96 ($count==1 ? "" : "s") ?> 97 </div> 98 </div> <!-- dlogScreen --> 99 <div class=cr> 100 <?php echo C_program . ", version " . C_version ?> 101 </div> 102 </body> 103 </html> 104 <?php 105 106 107 // 108 // Else doesn't happen 109 // 110 111 } else { 112 die("Unknown mode"); 113 } 114 115 ?>
End of listing