smalot / smalot/pdfparser

Returns Blank, no errors, after saved through imap_fetch and decoded based on encoding.

Open
#183 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PHP
Stars
2.7k
Forks
579
Avg merge
2m
Merged PRs (30d)
1

Description

Hi there,

Hoping you can help, I am very close, I think. I suspect my issue is with how the decoding of a pdf file works when saving via imap_fetch.

My test pdf file works fine when I save it from gmail, and upload it to the demo page, and also when I save it from gmail and ftp it over to my pdfdemos folder to test with test.php - so I know the pdfparser is functioning as intended/expected on my server.

But when the test pdf file arrives at the pdfparser on my server via my php script which logs into my gmail using imap_open, and later saves the attachment from a selected email using imap_fetch...the pdfparser returns a blank page (no errors).

I think it comes down to a section of code where the attachment is decoded from one of two types of encoding just prior to getting saved to the server. This is the relevant chunk of code, any advice is welcome, even if you think the problem is elsewhere ( I can post more code):

if($attachments[$i]['is_attachment']) {
$attachments[$i]['attachment'] = imap_fetchbody($inbox, $email_number, $i+1);
if($structure->parts[$i]->encoding == 3) { // 3 = BASE64
$attachments[$i]['attachment'] = base64_decode($attachments[$i]['attachment']);
}
elseif($structure->parts[$i]->encoding == 4) { // 4 = QUOTED-PRINTABLE
$attachments[$i]['attachment'] = quoted_printable_decode($attachments[$i]['attachment']);
}
}

The PDF files that result from this all look as expected to me in acrobat, they just won't parse once processed this way.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Begin with the PHP script's imap_open and imap_fetch path, comparing the saved attachment with the Gmail/FTP version using test.php and the demo page. Trace the encoding branch shown in the report and verify whether the resulting PDF can be parsed without a blank page. The issue is complete when the cause and a reproducible diagnosis or fix are documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.