Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PDF not possible to be viewed in the browser #867

Closed
phsc84 opened this issue Jan 20, 2023 · 9 comments
Closed

PDF not possible to be viewed in the browser #867

phsc84 opened this issue Jan 20, 2023 · 9 comments
Labels
bug Something isn't working

Comments

@phsc84
Copy link

phsc84 commented Jan 20, 2023

Describe the bug
PDFs should have the option to be viewed in the browser or to be downloaded.

PDF with no option to be viewed in the browser
----boundary_2799_4e1e27b0-e322-4f60-97c3-45bf9cd8e113
Content-Type: application/octet-stream; name="2022-000182500_a.pdf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment
X-EC0D2A8E-5CB7-4969-9C36-46D859D137BE-PartID: {A7EC3E57-0EE9-40EC-821A-16B5CC8340DF}

PDF with option to be viewed in the browser
--b66120d3-6d65-4e54-a6cb-f7dfb8e086a1-1
Content-Type: application/pdf;
name="180717_factsheet.pdf"
Content-Disposition: attachment;
filename="180717_factsheet.pdf"
Content-Transfer-Encoding: base64

Please complete the following information:

  • Browser: Chrome 109
  • PHP version: 8.1
  • SnappyMail Version: 2.24.5

Additional context
The problem does not exist in SnappyMail 2.22.5.

@the-djmaze
Copy link
Owner

the-djmaze commented Jan 20, 2023

Strange as this was fixed in your #144 issue.

I have one email that has

Content-Type: application/octet-stream; name=20210420.pdf
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename=20210420.pdf

And it does open properly in my browser.

You can modify the following code and hope to find the issue.

// https://github.com/the-djmaze/snappymail/issues/144
if ('.pdf' === \substr($sFileNameIn,-4)) {
$sContentTypeOut = 'application/pdf'; // application/octet-stream
} else {
$sContentTypeOut = $sContentTypeIn
?: \SnappyMail\File\MimeType::fromFilename($sFileNameIn)
?: 'application/octet-stream';
}

Maybe start with something like:

// https://github.com/the-djmaze/snappymail/issues/144
if ('.pdf' === \substr($sFileNameIn,-4)) {
	$sContentTypeOut = 'application/pdf'; // application/octet-stream
error_log("Output {$sFileNameIn} forced PDF");
} else {
	$sContentTypeOut = $sContentTypeIn
		?: \SnappyMail\File\MimeType::fromFilename($sFileNameIn)
		?: 'application/octet-stream';
error_log("Output {$sFileNameIn} as {$sContentTypeOut}");
}

@phsc84
Copy link
Author

phsc84 commented Jan 20, 2023

I've modified the file Raw.php and added the code you suggested. Unfortunately, nothing popped up in the logs, even with log level 7 (=debug).

Then I've modified the file as follows, because I wanted to be sure, that the program enters the if (!empty($sFileHashIn)) {.

error_log("ContentTypeIn {$sContentTypeIn} FileNameIn {$sFileNameIn} FileHashIn {$sFileHashIn}");

		if (!empty($sFileHashIn)) {
			$this->verifyCacheByKey($sRawKey);

// https://github.com/the-djmaze/snappymail/issues/144
if ('.pdf' === \substr($sFileNameIn,-4)) {
	$sContentTypeOut = 'application/pdf'; // application/octet-stream
error_log("Output {$sFileNameIn} forced PDF");
} else {
	$sContentTypeOut = $sContentTypeIn
		?: \SnappyMail\File\MimeType::fromFilename($sFileNameIn)
		?: 'application/octet-stream';
error_log("Output {$sFileNameIn} as {$sContentTypeOut}");
}

But even with that I don't get any log output. Strange...

Do you have an idea what else I could try?

@the-djmaze
Copy link
Owner

I've overlooked that there is another part a bit lower.
Maybe that is triggered and fails.

if ('.pdf' === \substr($sFileName, -4)) {
// https://github.com/the-djmaze/snappymail/issues/144
$sContentType = 'application/pdf';
} else {
$sContentType = $sContentTypeIn
?: $sContentType
// ?: \SnappyMail\File\MimeType::fromStream($rResource, $sFileName)
?: \SnappyMail\File\MimeType::fromFilename($sFileName)
?: 'application/octet-stream';
}

@phsc84
Copy link
Author

phsc84 commented Jan 20, 2023

Even if I add the error_log statements in this part, I don't get any logs. When activating the debug mode, I get the following, but I doubt, this will help much...
[2023-01-20 21:02:22.062][241e27d1] IMAP[INFO]: < * 18 FETCH (UID 13507 RFC822.SIZE 86893 INTERNALDATE "17-Jan-2023 10:02:23 +0100" FLAGS (\Seen $Forwarded) BODYSTRUCTURE ((("text" "html" ("charset" "utf-8") NIL NIL "base64" 19118 245 NIL NIL NIL NIL)("application" "octet-stream" ("name" "2022-000182500_a.pdf") NIL NIL "base64" 53606 NIL ("attachment" NIL) NIL NIL) "mixed" ("boundary" "--boundary_2799_4e1e27b0-e322-4f60-97c3-45bf9cd8e113") NIL NIL NIL)("application" "pkcs7-signature" ("name" "smime.p7s") NIL NIL "base64" 10994 NIL ("attachment" ("filename" "smime.p7s")) NIL NIL) "signed" ("protocol" "application/pkcs7-signature" "micalg" "sha-256" "boundary" "----A0EA02B57E456D7764E38D2EDBEA7E15") NIL NIL NIL) BODY[HEADER.FIELDS (RETURN-PATH RECEIVED MIME-VERSION MESSAGE-ID CONTENT-TYPE FROM TO CC BCC SENDER REPLY-TO DELIVERED-TO IN-REPLY-TO REFERENCES DATE SUBJECT X-MSMAIL-PRIORITY IMPORTANCE X-PRIORITY X-DRAFT-INFO RETURN-RECEIPT-TO DISPOSITION-NOTIFICATION-TO X-CONFIRM-READING-TO AUTHENTICATION-RESULTS X-DKIM-AUTHENTICATION-RESULTS LIST-UNSUBSCRIBE AUTOCRYPT X-SPAM-STATUS X-SPAMD-RESULT X-BOGOSITY X-VIRUS X-VIRUS-SCANNED X-VIRUS-STATUS)] {1553}\r\n

@phsc84
Copy link
Author

phsc84 commented Jan 22, 2023

My Raw.php file (had to rename it to Raw.txt in order to upload it) meanwhile looks as follows, but I don't get any output in the log (log level 4, debug mode activated).
Raw.txt

the-djmaze pushed a commit that referenced this issue Jan 22, 2023
@the-djmaze
Copy link
Owner

I've made a change to better log it.

Use that and disable cache in application.ini / Admin -> Config
Then it should properly log info and hopefully disable browser cache.

@phsc84
Copy link
Author

phsc84 commented Jan 22, 2023

Wonderful, now I get log output. It shows the following:
[2023-01-22 10:12:55.288][3aecbea3] RAW[DEBUG]: Array
(
[0] => 2022-000182500_a.pdf
[1] => application/octet-stream
[2] =>
[3] => application/octet-stream
)

the-djmaze pushed a commit that referenced this issue Jan 22, 2023
@the-djmaze
Copy link
Owner

I think i found the issue with above commit.

@phsc84
Copy link
Author

phsc84 commented Jan 22, 2023

Fantastic! I've applied the patch and now it works like a charm again. Thank you very much!

@phsc84 phsc84 closed this as completed Jan 22, 2023
@the-djmaze the-djmaze added the bug Something isn't working label Jan 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants