Possible solution for the PDF gets corrupted issue
Reinier van Wijngaarden
rvanwijn at XS4ALL.NL
Thu Sep 16 22:48:40 IST 2004
I saw a lot of people here having trouble with some PDFs in conjuction
with MS Outlook & MS Outlook Express which gets corrupted.
I had the same problem, but found a possible fix. I tried it and it worked
perfectly.
I had saved some originel PDF's which gets corrupted the moment I send
them through MailScanner.
They all worked fine now.
The solution I found was in de FreeBSD corner:
http://www.mail-archive.com/mimedefang@lists.roaringpenguin.com/msg05058.html
I picked out the file: QuotedPrint.pm and copied it over the existing file
in:
/usr/lib/perl5/site_perl/5.6.1/MIME/Decoder/QuotedPrint.pm
ofcourse then launch the command: service MailScanner restart
And it worked perfectly. This is a piece out of the file with the code.
BUT CAUTION ....in the next update of MailScanner the Mime-tools are being
updated there is a chance that this will overwrite your newly installed
QuotedPrint.pm.
Good luke hope this one works for you also !! Thanx goes to Martin Blapp !
--- lib/MIME/Decoder/QuotedPrint.pm.orig Tue Aug 31 17:02:43 2004
+++ lib/MIME/Decoder/QuotedPrint.pm Tue Aug 31 17:02:38 2004
@@ -85,9 +85,37 @@
#
sub decode_it {
my ($self, $in, $out) = @_;
+ my $init = 0;
+ my $badpdf = 0;
while (defined($_ = $in->getline)) {
- $out->print(decode_qp($_));
+ #
+ # Dirty hack to fix QP-Encoded PDFs from MS-Outlook.
+ #
+ # Check if we have a PDF file and if it has been encoded
+ # on Windows. Unix encoded files are fine. If we have
+ # one encoded CR after the PDF init string but are missing
+ # an encoded CR before the newline this means the PDF is broken.
+ #
+ if (!$init) {
+ $init = 1;
+ if ($_ =~ /^%PDF-[0-9\.]+=0D/ && $_ !~ /(?!=0D)\n$/) {
+ $badpdf = 1;
+ }
+ }
+ #
+ # Decode everything with decode_qp() except corrupted PDFs.
+ #
+ if ($badpdf) {
+ my $output = $_;
+ $output =~ s/[ \t]+?(\r?\n)/$1/g;
+ $output =~ s/=\r?\n//g;
+ $output =~ s/(^$|[^\r])\n\Z/$1\r\n/;
+ $output =~ s/=([\da-fA-F]{2})/pack("C", hex($1))/ge;
+ $out->print($output);
+ } else {
+ $out->print(decode_qp($_));
+ }
}
1;
}
------------------------ MailScanner list ------------------------
To unsubscribe, email jiscmail at jiscmail.ac.uk with the words:
'leave mailscanner' in the body of the email.
Before posting, read the MAQ (http://www.mailscanner.biz/maq/) and
the archives (http://www.jiscmail.ac.uk/lists/mailscanner.html).
More information about the MailScanner
mailing list