писал под свои нужды года два назад скрипт, получающий через сокеты мыло:
<?php
function read_chunk() {
list($cmd)=func_get_args();
global $pop;
$_out='';
$_tmp='';
fputs($pop,"${cmd}\n");
while (!feof($pop)) {
$_out=fgets($pop);
if (preg_match("/^\./",$_out)) { break; }
$_tmp.=$_out;
}
return($_tmp);
}
#-------------------------------------------
#open socket
$pop=fsockopen($_server,110,$errno,$errstr,30) or die ("Error! Unable to connect mail-server!");
if (!strstr(fgets($pop),"+OK")) {die('ERROR: cannot connect to server!'); }
fputs($pop,"user ${_user}\n");
fputs($pop,"pass ${_pwd}\n");
$_out=fgets($pop);
if (strstr($_out,"Mailbox is busy")) { echo 'ERROR: Another pop session in mailbox!';fclose($pop);exit;}
elseif (strstr($_out,"is incorrect")) { echo 'ERROR: Authorization failed!';fclose($pop);exit;}
$_out=fgets($pop);
if (preg_match("/has (\d+) messages/",$_out,$z)) {
if ($z[1]==0) { echo "No messages in mailbox!<br>\n"; exit; }
echo "Messages in mailbox: ${z[1]}\n<br>";
} else { echo 'connection failed!';fclose($pop);exit;}
$msg=array();
$_header=array();
$_date=array();
while ($z[1]>0) {
$_header=read_chunk("top ${z[1]} 0");
#from gmail.com <--- в данном случае ищутся все письма пришедшие с gmail
if (strstr($_header,"gmail.com")) {
# !!!! вот здесь вместо "двоеточие правая скобка" автозамена на
![icon_sad.gif](/template/images/smiles/icon_sad.gif)
на форуме
preg_match("/gmail\.com.* (\w+) (\d+) (\d+)
![icon_sad.gif](/template/images/smiles/icon_sad.gif)
\d+)
![icon_sad.gif](/template/images/smiles/icon_sad.gif)
\d+)/",$_header,$ok);
#checking date
if ($_date[0]!='') {
if ($ok[2]==$_date[2]) { $msg[]=$z[1]; }
elseif ($ok[3] < $_date[3]) { break; }
else { $msg[]=$z[1]; }
} else { $_date=$ok; $msg[]=$z[1];}
}
$z[1]--;
}
$num=0;
echo "found ".count($msg)." messages for last 24h<br>\nProcessing mail...\n";
#get messages
$result=array();
foreach($msg as $i) {
$result[]=read_chunk("retr ${i}");
if (strlen($result)<100) { echo "failed!<br>\n"; continue; }
}
echo "done!\n";
#logout
fputs($pop,"quit\n");
fclose($pop);
?>