barbushin / php-imap

Manage mailboxes, filter/get/delete emails in PHP (supports IMAP/POP3/NNTP)
MIT License
1.65k stars 459 forks source link

I am using php 7.3 and php-imap 4.2.1, and the content of my email is garbled, and the Chinese string is converted into characters! #625

Closed sunnyzss928 closed 2 years ago

sunnyzss928 commented 2 years ago

Environment (please complete the following information):

Your Text I am using php 7.3 and php-imap 4.2.1, and the content of my email is garbled, and the Chinese string is converted into characters!

example: ���Ǽ���

My code for getting email details:

` public function construct(){ parent::construct();

     //判断是否是业务登入查询自身邮件
     $hoststring = '{imap.exmail.qq.com:993/imap/ssl/novalidate-cert}INBOX';
     $username   = session('admin')['email'];
     $password   = session('admin')['authorization_code'];
     $url        = ROOT_PATH .'public' .DS. 'email_file/';
     $coding     = "UTF-8";
     $this->mailbox = new PhpImap\Mailbox($hoststring, $username, $password,$url,$coding);

 }

/**
 * Mail details
 */
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";
    }

  $mail->embedImageAttachments();

  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;
    }

     // Get attachments
    if (!$this->mailbox->getAttachmentsIgnore()) {
        $attachments = $mail->getAttachments();

        foreach ($attachments as $attachment) {
            echo ''.'https://score.wanzhicoil.com/email_file/'.(string) $attachment->name.': '.(string) $attachment->fileExtension;
        }
    }

     // Save attachments one by one
    // if (!$this->mailbox->getAttachmentsIgnore()) {
    //     $attachments = $mail->getAttachments();

    //     foreach ($attachments as $attachment) {
    //         echo '--> Saving '.(string) $attachment->name.'...';

    //         // Set individually filePath for each single attachment
    //         // In this case, every file will get the current Unix timestamp
    //         $attachment->setFilePath(ROOT_PATH . 'public' .DS.'email_file/'.$attachment->name);

    //         if ($attachment->saveToDisk()) {
    //             echo "OK, saved!\n";
    //         } else {
    //             echo "ERROR, could not save!\n";
    //         }
    //     }
    // }

    }

`

sunnyzss928 commented 2 years ago

When I use php-imap 3.1.0, my Chinese can be displayed, but the pictures cannot be displayed. I am currently using php-imap 4.2.1, and the content of my Chinese email is garbled, so I want to know how to solve it! thanks

Sebbo94BY commented 2 years ago

Thanks for testing and figuring out, where it worked as expected.

Here are the respective changes between those two versions: https://github.com/barbushin/php-imap/compare/3.1.0...4.2.1

It needs to be checked, which of these changes broke this behaviour.

Sebbo94BY commented 2 years ago

Can you please test again with the latest release 4.3.0 and let us know, if the issue has been resolved now or if it still persists?

Sebbo94BY commented 2 years ago

I've just released a new version 4.5.3 with some more improvements regarding these encoding issues and some unit tests.

Relates to #657.

Feel free to reopen this issue, if you should be still able to reproduce your issue(s) or just open a new ticket.