blob: 7f5da10e9bcb0929bf56f235e7137dc766bfe712 (
plain) (
blame)
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
|
--- 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($output));
+ }
}
1;
}
|