Hello,
I've written this code in order to get rid of useless mails (spam) but I've failed to include one more feature : strip all html tags from the parsed message and preserve its attachments at the same time.
The problem is that I don't know where to apply the strip_tags function in a safe and efficient way.
Here is the code :
/* START PROCESS --------------------------------------------------------------------------*/
if($check) {
$mess_num_all = $check->Nmsgs;
$mess_num_unread = $check->Recent;
$mess_first_unread = ($mess_num_all - $mess_num_unread) + 1;
if($mess_num_unread == 0) {
} else {
for($i=$mess_first_unread; $i <= $mess_num_all; $i++ ) {
$header = imap_header($mbox, $i);
$mess_header = imap_fetchheader($mbox, $i);
$mess_subject = $header->subject;
$mess_from_full = $header->fromaddress;
$mess_from_adr = trim(str_replace("<", "", str_replace(">", "", strstr($header->fromaddress, '<'))));
$mess_date = date("Y-m-d",$header->udate);
$mess_time = date("H:i",$header->udate);
$mess_body = imap_body($mbox, $i);
$is_spam = "";
// check sender
for($j=0; $j < sizeof($bad_from_string); $j++ ) {
if(stristr($mess_from_full, $bad_from_string[$j])) $is_spam = "yes";
}
// check header
if($is_span != "yes") {
for($j=0; $j < sizeof($bad_header_string); $j++ ) {
if(stristr($mess_header, $bad_header_string[$j])) $is_spam = "yes";
}
} else {
}
// check subject
if($is_span != "yes") {
for($j=0; $j < sizeof($bad_sub_string); $j++ ) {
if(stristr($mess_header, $bad_sub_string[$j])) $is_spam = "yes";
}
} else {
}
// check body
if($is_span != "yes") {
for($j=0; $j < sizeof($bad_body_string); $j++ ) {
if(stristr($mess_header, $bad_body_string[$j])) $is_spam = "yes";
}
} else {
}
// decide action
if($is_spam == "yes") imap_delete($mbox, $i);
// finally strip html tags from message and preserve attachments at the same time
???????????????????????????
}
}
} else {
}
imap_close($mbox, CL_EXPUNGE);
I've written this code in order to get rid of useless mails (spam) but I've failed to include one more feature : strip all html tags from the parsed message and preserve its attachments at the same time.
The problem is that I don't know where to apply the strip_tags function in a safe and efficient way.
Here is the code :
/* START PROCESS --------------------------------------------------------------------------*/
if($check) {
$mess_num_all = $check->Nmsgs;
$mess_num_unread = $check->Recent;
$mess_first_unread = ($mess_num_all - $mess_num_unread) + 1;
if($mess_num_unread == 0) {
} else {
for($i=$mess_first_unread; $i <= $mess_num_all; $i++ ) {
$header = imap_header($mbox, $i);
$mess_header = imap_fetchheader($mbox, $i);
$mess_subject = $header->subject;
$mess_from_full = $header->fromaddress;
$mess_from_adr = trim(str_replace("<", "", str_replace(">", "", strstr($header->fromaddress, '<'))));
$mess_date = date("Y-m-d",$header->udate);
$mess_time = date("H:i",$header->udate);
$mess_body = imap_body($mbox, $i);
$is_spam = "";
// check sender
for($j=0; $j < sizeof($bad_from_string); $j++ ) {
if(stristr($mess_from_full, $bad_from_string[$j])) $is_spam = "yes";
}
// check header
if($is_span != "yes") {
for($j=0; $j < sizeof($bad_header_string); $j++ ) {
if(stristr($mess_header, $bad_header_string[$j])) $is_spam = "yes";
}
} else {
}
// check subject
if($is_span != "yes") {
for($j=0; $j < sizeof($bad_sub_string); $j++ ) {
if(stristr($mess_header, $bad_sub_string[$j])) $is_spam = "yes";
}
} else {
}
// check body
if($is_span != "yes") {
for($j=0; $j < sizeof($bad_body_string); $j++ ) {
if(stristr($mess_header, $bad_body_string[$j])) $is_spam = "yes";
}
} else {
}
// decide action
if($is_spam == "yes") imap_delete($mbox, $i);
// finally strip html tags from message and preserve attachments at the same time
???????????????????????????
}
}
} else {
}
imap_close($mbox, CL_EXPUNGE);