Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
08-27-2006, 12:44 AM #1
- Join Date
- Dec 2005
- Thanked 0 Times in 0 Posts
Using GREP to display the subject of a mail message
Okay, I've been looking around trying to find a way to do this, and I can't figure it out so far. I'm still a real novice at PHP coding, and I'm pretty much stuck at this point. I have a PHP file that will automatically parse a directory listing for any given directory into a nice and pretty format, but what I'm using it for requires some additional functionality that I can't quite figure out.
I want to list the contents of the mail folders on a linux system (no problem with that part), but I want the page to display the subject of the mail files rather than the actual file names. It will also need to display the "from" information from the mail message. The only way that I can think to do this is using the Unix GREP command. I've found ways to make the PHP code actually GREP the file, but I can't figure out how to actually show exactly what I want.
The basic functionality of the page is like this at the moment:
$arsize = sizeof($files);
if (strrpos($files[$i], '.'))
($ext = strtolower(substr($files[$i], strrpos($files[$i], '.')+1)));
else ($ext = '');
$icon = $filetypes[$ext];
$filename = $files[$i];
$filename = substr($files[$i], 0, 40) . '...';
$fileurl = $leadon . $files[$i];
$fileurl = $_SESSION['PHP_SELF'] . '?dir=' . urlencode($leadon) . '&download=' . urlencode($files[$i]);
<tr class="<?=$class;?>" id="listing">
<td width="24" align="center" valign="middle">
<input type="checkbox" />
<td width="16" align="center" valign="middle">
<a href="<?=$fileurl;?>"><img src="dlf/<?=$icon;?>" alt="<?=$files[$i];?>" /></a>
<td width="300" align="left" valign="middle">
<td width="170" align="right" valign="middle">
<td width="250" align="right" valign="middle">
<?=date ("M d Y h:i:s A", filemtime($leadon.$files[$i]));?>
$handle = popen('grep --max-count=1 Subject: /path/to/file.txt', 'r');
$output = fread($handle, 2096);
Any suggestions anyone may have on how to do this would be greatly appreciated. Thank you for your time.