1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
| <?php
header("Content-Type: text/html; charset=iso-8859-15");
$nom_fichier = "";
$mail = imap_open("{pop3.****.fr:143}INBOX","monmail","monMDP");
$nbmess = imap_num_msg($mail);
if ($nbmess == 0)
{
echo "<div align='center'> <b>Aucun message présent sur le serveur</b><br /><br /></div>";
}
else
{
for($j=1;$j<=$nbmess;$j++)
{
$header = imap_headerinfo($mail,$j);
$sujet = $header->subject;
$struct = imap_fetchstructure($mail,$j);
if ($struct->type == 1)
{
$nbrparts = !$struct->parts ? "1" : count($struct->parts);
}
$piece = array();
for($h=1;$h<=$nbrparts;$h++)
{
$part = $struct->parts[1];
$piece = imap_fetchbody($mail,$j,$h+1);
if ($part->encoding == "3")
{
$nbparam = count($part->parameters);
$i=0;
while($i<$nbparam)
{
$i++;
$param = $part->parameters[$i];
$nom_fichier = $struct->parts[$h]->dparameters[0]->value;
if($nom_fichier!=null)
{
echo ' Nom du fichier : '.$nom_fichier.'<br>';
}
}
$piece = imap_base64($piece);
}
if($nom_fichier!=null)
{
$newfichier = fopen("C:/test/".$nom_fichier,"w+");
fwrite($newfichier,$piece);
fclose($newfichier);
}
}
}
}
?> |
Partager