Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-27-2006, 12:44 AM   PM User | #1
G_Hosa_Phat
New to the CF scene

 
Join Date: Dec 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
G_Hosa_Phat is an unknown quantity at this point
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:
PHP Code:
 $arsize = sizeof($files);
for($i=0;$i<$arsize;$i++) {
if (strrpos($files[$i], '.'))
($ext = strtolower(substr($files[$i], strrpos($files[$i], '.')+1)));
else ($ext = '');
 
if($filetypes[$ext]) {
$icon = $filetypes[$ext];
}
 
$filename = $files[$i];
if(strlen($filename)>43) {
$filename = substr($files[$i], 0, 40) . '...';
}
 
$fileurl = $leadon . $files[$i];
if($forcedownloads) {
$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>
<td width="16" align="center" valign="middle">
<a href="<?=$fileurl;?>"><img src="dlf/<?=$icon;?>" alt="<?=$files[$i];?>" /></a>
</td>
<td width="300" align="left" valign="middle">
<a href="<?=$fileurl;?>"><strong><?=$filename;?></strong></a>
</td>
<td width="170" align="right" valign="middle">
<em><?=round(filesize($leadon.$files[$i])/1024);?>KB</em>
</td>
<td width="250" align="right" valign="middle">
<?=date ("M d Y h:i:s A"filemtime($leadon.$files[$i]));?>
</td>
</tr>
I'm thinking I should be able to use some code to GREP the actual files to find the literal string "Subject:", but then I'm not sure how to actually pull what should BE the subject into a variable to display. I found the following code floating around on the Net for doing the GREP (although I'm not entirely sure I understand it all, but I'm gonna do some research on that part in a bit):
PHP Code:
$handle popen('grep --max-count=1 Subject: /path/to/file.txt''r');
$output fread($handle2096);
pclose($handle); 
I figure I can use this to find the line where the subject of the message is, so the trick becomes how to get that subject setup into a variable for display in the table. Then, of course, I'm going to need to do the same basic thing for the "From:" part of the message as well.

Any suggestions anyone may have on how to do this would be greatly appreciated. Thank you for your time.
G_Hosa_Phat is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:11 PM.


Advertisement
Log in to turn off these ads.