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 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
| $overview = imap_fetch_overview($mbox,"1:$mailnumber",0);
if(is_array($overview)) {
if(isset($message)) {
echo $message;
} else {
$nbm = sizeof($overview);
for($i= $nbm-1; $i >= 0; $i--){
$val = $overview[$i];
$nb = $val->msgno;
$rawsubject = imap_mime_header_decode($val->subject);
$subject = $rawsubject[0]->text;
if($subject == '') {$subject = "(no subject)";};
//$from = htmlspecialchars($val->from);
$from = $val->from;
$db_date = $val->date;
$db_sender = $from;
$db_taille = $val->size;
$db_emailto = $username;
$db_subject = $subject;
$db_statut = 'nonlu';
# recuperation du corp du mail
$struct = imap_fetchstructure($mbox,$nb);
$db_body_type = get_mime_type($struct);
$db_body = get_part($mbox,$nb,$db_body_type);
# recuperation de la piece jointe
if(isset($struct->parts)){
while (list ($key, $val) = each ($struct->parts))
{
if($key > 0)
{
if($val->ifparameters)
{
$aparamdetail = $val->parameters;
$nom_fichier = $aparamdetail[0]->value; /// nom fichier
$partnumber=$key;
}
else
{
$partnumber=$key;
$nom_fichier = '';
};
$attach_body = imap_fetchbody($mbox,$nb, $key+1);
$atype = $struct->parts[$partnumber]->type;
if($atype == "") $atype = 0; // Text
$asubtype = $struct->parts[$partnumber]->subtype;
if($asubtype == "") $asubtype = 'PLAIN';
$attach_type = $mimetype[$atype]."/".$asubtype;
$attach_name = $struct->parts[$partnumber]->parameters[0]->value;
if($attach_name = '') $attach_name = 'noname';
$anencode = $struct->parts[$partnumber]->encoding;
if($anencode == 3){
$return_content = imap_base64($attach_body);
} else if($anencode == 4){
$return_content = imap_qprint($attach_body);
} else {
$return_content = $attach_body;
};
$nom_fichier = $attach_name;
if($nom_fichier > ''){
//Ouverture du fichier et création s'il n'existe pas
$link_pj = 'C:/Program Files/EasyPHP1-8/www/webmail/pj/'.$nom_fichier;
$newfichier = fopen($link_pj,"w+");
//Ecriture dans le fichier
fwrite($newfichier,$return_content);
//Fermeture du fichier
fclose($newfichier);
}
};
}; /// if key
}; /// while
# insertion des mails dans la base si mail client
$mail_client = FALSE;
while ($cust_row = mysql_fetch_array($base_result_cust, MYSQL_BOTH))
{
if($db_sender == $cust_row['customers_email_address']){
$mail_client = TRUE;
break;
}
}
if($mail_client)
{
$base_insert = "INSERT INTO email_log VALUES ('','','','$db_date','$db_taille','$db_sender','$db_emailto','$db_subject','$db_body','$db_body_type','','$db_statut')";
$result_insert = mysql_query($base_insert) or die("Query failed L165");
$nb_mail_non_lu++;
$nb_mail_total++;
# Suppression du mail
delete_mail($server, $username, $password,$mbox,$nb);
}//if mail_client
}; /// for nbm
}; /// if message
}; /// if overview |
Partager