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

The attachments in the mail I received cannot be displayed, including pictures. Why does the name of the file saved locally end in .bin? #622

Closed
sunnyzss928 opened this issue Nov 22, 2021 · 8 comments
Labels
enhancement This will enhance this library. not supported This is not or can not be supported by this library as it is technically not possible.

Comments

@sunnyzss928
Copy link

sunnyzss928 commented Nov 22, 2021

The attachments in the mail I received cannot be displayed, including pictures.
Why does the name of the file saved locally end in .bin?

$fileSysName = \bin2hex(\random_bytes(16)).'.bin'; $filePath = $attachmentsDir.DIRECTORY_SEPARATOR.$fileSysName;

Why did the ending become .bin? Pictures and attachments can't be displayed in my email details, only text.

Below is my code for calling php-imap:

public function get_emailinfo($ids)
{ 
    if($this->request->isGet()){
        
        //Email content details
        $mail = $this->mailbox->getMail((int)$ids, true);
    
        //Determine whether there are attachments
        if ($mail->hasAttachments()) {
            
            echo "Yes\n".count($mail->getAttachments())." attachements\n";
            
        } else {
            
            echo "No\n";
        }

        if ($mail->textHtml) {

            $mailcontent = $mail->textHtml;
            $mailcontent = str_replace('cid:',"/email_file/",$mailcontent);

            $this->view->assign(["headermail"=>$mail,"mailcontent"=>$mailcontent]);  
        } else {
            echo "Message Plain:\n".$mail->textPlain;
        }        
    }
    
    return $this->view->fetch();
}
@sunnyzss928 sunnyzss928 added the needs investigation This will be tested / debugged or checked out. label Nov 22, 2021
@Sebbo94BY
Copy link
Collaborator

Since multiple emails could contain the same email attachment, all locally saved files get a random file name plus the suffix .bin, which I guess simply stays for binary.

There is an open pull request to also support the original file name: #589 (still waiting for feedback from the author)

Why are you replacing all cid: with /email_file/ in the $mailcontent?

$mailcontent = str_replace('cid:',"/email_file/",$mailcontent);

These cid: blocks are references to the attachments. So if you want to display your attachment "inline", then you need to replace this e.g. cid:whatever.png code with the path to the downloaded and saved file, which currently might be kinda tricky or even impossible as the saved files get random file names. I'll try to implement the original file name logic, if the pull request shouldn't get merged by end of the week.

To be able to better help you: How does your output currently look like and how do you expect it to look like?

@sunnyzss928
Copy link
Author

Since multiple emails could contain the same email attachment, all locally saved files get a random file name plus the suffix .bin, which I guess simply stays for binary.

There is an open pull request to also support the original file name: #589 (still waiting for feedback from the author)

Why are you replacing all cid: with /email_file/ in the $mailcontent?

$mailcontent = str_replace('cid:',"/email_file/",$mailcontent);

These cid: blocks are references to the attachments. So if you want to display your attachment "inline", then you need to replace this e.g. cid:whatever.png code with the path to the downloaded and saved file, which currently might be kinda tricky or even impossible as the saved files get random file names. I'll try to implement the original file name logic, if the pull request shouldn't get merged by end of the week.

To be able to better help you: How does your output currently look like and how do you expect it to look like?

My problem now is that pictures and attachments cannot be displayed in emails, so I use “str_replace()“ to replace my picture address. I tried to modify the save file address and name in "downloadAttachment", and put the pictures and attachments in a fixed folder "/public/email_file".

If I don’t do this, how can I call the binary file.bin in my email and display it in my email. In the content?

I am very anxious now, I am in Zhengzhou, China, waiting for your reply online.Thank you!

@sunnyzss928
Copy link
Author

Since multiple emails could contain the same email attachment, all locally saved files get a random file name plus the suffix .bin, which I guess simply stays for binary.

There is an open pull request to also support the original file name: #589 (still waiting for feedback from the author)

Why are you replacing all cid: with /email_file/ in the $mailcontent?

$mailcontent = str_replace('cid:',"/email_file/",$mailcontent);

These cid: blocks are references to the attachments. So if you want to display your attachment "inline", then you need to replace this e.g. cid:whatever.png code with the path to the downloaded and saved file, which currently might be kinda tricky or even impossible as the saved files get random file names. I'll try to implement the original file name logic, if the pull request shouldn't get merged by end of the week.

To be able to better help you: How does your output currently look like and how do you expect it to look like?

This is my email number: sunnyzss928@qq.com .We can communicate in time via email.

@sunnyzss928
Copy link
Author

Since multiple emails could contain the same email attachment, all locally saved files get a random file name plus the suffix .bin, which I guess simply stays for binary.

There is an open pull request to also support the original file name: #589 (still waiting for feedback from the author)

Why are you replacing all cid: with /email_file/ in the $mailcontent?

$mailcontent = str_replace('cid:',"/email_file/",$mailcontent);

These cid: blocks are references to the attachments. So if you want to display your attachment "inline", then you need to replace this e.g. cid:whatever.png code with the path to the downloaded and saved file, which currently might be kinda tricky or even impossible as the saved files get random file names. I'll try to implement the original file name logic, if the pull request shouldn't get merged by end of the week.

To be able to better help you: How does your output currently look like and how do you expect it to look like?

The php-imap version I currently use is 3.1.0

@Sebbo94BY
Copy link
Collaborator

I guess I've understood your use-case and the problem.

I think, you need to wait until this change has been implemented: #589

This will result in the identical file names, which are referenced in the email content.

@Sebbo94BY Sebbo94BY added enhancement This will enhance this library. not supported This is not or can not be supported by this library as it is technically not possible. and removed needs investigation This will be tested / debugged or checked out. labels Nov 23, 2021
@sunnyzss928
Copy link
Author

我想我已经了解您的用例和问题。

我认为,您需要等到此更改实施:#589

这将导致在电子邮件内容中引用的相同文件名。

ok ,I used php 7.3 and php-imap 4.2.1, and the pictures can be displayed in the email.
For the attachment, I used the splicing save address and file name.

@Sebbo94BY
Copy link
Collaborator

The develop branch contains now a change to support the original filename of attachments. Here, you can find more information about this change: #633

@Sebbo94BY
Copy link
Collaborator

The support for the original filename is included in the release 4.3.0 and newer.

Let us know, if this helps to solve your use case here or if still need any further support.

Closing this issue for now. Feel free to comment or re-open it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement This will enhance this library. not supported This is not or can not be supported by this library as it is technically not possible.
Projects
None yet
Development

No branches or pull requests

2 participants