This script checks the modified date on a Postfix mailbox folder.
The issue is, I have more than one location that needs to be check.
Folder /mnt/mail1/ contains mail dirs a,b,d,g
Folder /mnt/mail2/ contains the rest c,e,f,h,........,x,z
The script is run simply via the URL https://URL/index.php?email=charlie@delta.com
I need the script to check in the correct mount point depending on the email address being checked. In the case above it should check in /mnt/mail2/d/e/delta.com/.....
Please help. I know 0 to nothing about php.
<?php
if (isset($_REQUEST["email"])) {
$emailaddress= trim($_REQUEST["email"]);
$emailparts = explode("@",$emailaddress);
if (sizeof($emailparts) != 2) {
print "invalid-email,,,,";
exit();
}
$username = $emailparts[0];
$domain = $emailparts[1];
$basedir = "/mnt/mail1/";
$livePrefix = $basedir;
$archivePrefix = $basedir."archive/";
$livePath = $livePrefix . substr($domain,0,1) . "/" . substr($domain,1,1) . "/" . $domain . "/" . substr($username,0,1) . "/" . $username;
$archivePath = $archivePrefix . $domain ;
$liveStat = stat( $livePath . "/" . "cur");
$archStat = false;
if ( file_exists( $archivePath ) && is_dir( $archivePrefix ) ) {
$arhiveDirs = scandir($archivePath);
foreach( $arhiveDirs as $i => $fname ) {
if ( stripos( $fname , $username . "-" ) !== false ) {
$archivePath = $archivePath . "/" . $fname ;
$archStat = stat( $archivePath . "/cur" );
break;
}
}
}
$status="lost" ;
if ( $liveStat != false ) {
$status = "live" . "," . date("Y-m-d H:i:s", $liveStat['mtime'] ) . "," . sizeof( scandir($livePath . "/new") ) . "," ;
} else if ($archStat != false ) {
$status = "archived,,,";
} else {
$status = "lost,,,";
}
if ($archStat != false ) {
$status = $status . date("Y-m-d H:i:s", $archStat['mtime'] ) . "," . sizeof( scandir($archivePath . "/new") ) ;
} else {
$status = $status . "," ;
}
print $status ;
exit();
} else {
print "error,,,,";
exit();
}
?>