Hexes
Programmer
- Oct 21, 2010
- 21
Good day all I have a problem with a testing of sorts. I have a server that receives mails with attachments. Now this server converts that to tiff and faxes it out bot some mails come in corrupt and the system gets the attachment mixed up with the body of the mail. The result is a 75 page fax with garble in it and it is wasting a lot of money.
Now what I need is a way to detect base64 code and remove it from the string before it ends up in the fax but how to check ?
Using :
base64_decode( $ body);
doesn’t work to many false positives.
Going the long way doesn’t work because base64 code slips past.
<?php
function base64_decode_fix( $ body, $strict = false )
{
if( $strict )
if( preg_match( '![^a-zA-Z0-9/+=]!', $ body) )
return( false );
return( base64_decode( $ body) );
}
?>
The thing that makes this hard is the fact that some mails have huge legitimate text bodies so looking for suspiciously long strings in the body doesn’t work well to many false positives.
Any ideas how to work around this ? and get rid of the base64 in the $body string ?
Now what I need is a way to detect base64 code and remove it from the string before it ends up in the fax but how to check ?
Using :
base64_decode( $ body);
doesn’t work to many false positives.
Going the long way doesn’t work because base64 code slips past.
<?php
function base64_decode_fix( $ body, $strict = false )
{
if( $strict )
if( preg_match( '![^a-zA-Z0-9/+=]!', $ body) )
return( false );
return( base64_decode( $ body) );
}
?>
The thing that makes this hard is the fact that some mails have huge legitimate text bodies so looking for suspiciously long strings in the body doesn’t work well to many false positives.
Any ideas how to work around this ? and get rid of the base64 in the $body string ?