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

Issue saving attachments after upgrading to 2.0 #214

Open
cwyant-hfg opened this issue Feb 13, 2023 · 1 comment
Open

Issue saving attachments after upgrading to 2.0 #214

cwyant-hfg opened this issue Feb 13, 2023 · 1 comment

Comments

@cwyant-hfg
Copy link

Hello, I am using mail-mime-parser on a server that receives incoming emails with WAV file attachments. Since upgrading to 2.0 and migrating from Ubuntu 18 to 22, I'm getting an occasional error when processing the incoming emails via a PHP script:

"PHP Fatal error: Uncaught Error: Call to a member function getFilename() on null"

I'm simply saving the WAV file on the server for processing, then deleting it. The code block is below:

// assume only one attachment
$attachment = $message->getAttachmentPart(0);
$fname = $attachment->getFilename();
$fpath = $tempPath . $fname;
$attachment->saveContent($fpath);
$audioFile = $fpath;

I don't recall this happening very often on the old server. I noticed in the documentation there's an additional line, "
$stream = $attachment->getContentStream();" for attachments. Is this necessary when I'm only saving the file? I'm unable to see the original emails to confirm that an attachment is indeed attached, but I can work on that. Any help would be appreciated.

@zbateson
Copy link
Owner

Hi @cwyant-hfg --

Nothing jumps out, from what you said it may be an issue with specific emails, you'll need to take a look at which emails are causing the issue to narrow it down (you could check if $attachment is null and write out the whole email instead, or log details about the email so you can look it up if you have access to it elsewhere).

$fname = $attachment->getFilename();
$fpath = $tempPath . $fname;

I'd also change this to: $fpath = tmpfile(); -- using the name provided in $attachment->getFilename() like that can be an issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants