Source of “pachyinc.php”.
55 lines, 1.9 KBytes.   Last modified 5:15 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 // Hook for pre-incorporating email // 12 // // 13 //////////////////////////////////////////////////////////////////////////// 14 15 // This script incorporates new mail for a user asynchronously. It is 16 // called running as www-data (same as the web server), with a user name as 17 // the command line argument, and with the user's derived H2 hash on stdin. 18 // This is achieved by a cron job running as root (to read the hash file), 19 // via su (to downgrade from root to www-data). 20 // 21 // The use of this script is all that requires us to keep the derived H2 22 // hash on disk, albeit readable only by root. 23 24 chdir(dirname($_SERVER["SCRIPT_FILENAME"])); 25 26 require("pachysql.php"); 27 require("pachyauth.php"); 28 require("pachylib.php"); 29 30 if (isset($_SERVER["argv"])) $argv = $_SERVER["argv"]; 31 if (isset($argv) && count($argv) == 2) $user = $argv[1]; 32 33 if (!isset($argv)) { 34 echo "Pachyinc is designed to be run from the command line\n"; 35 } else if (!isset($user)) { 36 echo "Usage: php " . $argv[0] . " username\n"; 37 } else { 38 $h2 = fread(STDIN, 1000); 39 if ($h2 == "") { 40 echo "Pachyinc requires the user's H2 hash on stdin\n"; 41 } else if (!connectDB($user, $h2)) { 42 echo "Pachyinc failed to login as $user\n"; 43 } else { 44 inc($user, $h2); 45 applyInboxFilter($user); 46 $count = countMsgsWithLabel($user, C_unread); 47 $rc = file_put_contents(C_partsDir . "/$user/msgcount", $count); 48 if ($rc === false) { 49 writeLog("user $user failed to write msgcount file"); 50 } 51 // no output on success: we're in a cron job 52 } 53 } 54 55 ?>
End of listing