0

I am using the imap extension that is built in PHP to read messages from an imap email and parse out the message and add it to a database of another system.

The problem is that the message come encoded. so I will have to first decode it and then add it to the database.

I can use the imap_fetchstructure() to find out what type of encoding is the message encoded with and from them I should be able to decode it.

so here is what I have done

$struct = imap_fetchstructure($this->conn, $id, 0);

                    if(isset($struct->encoding)){
                        $message = $this->_decodeMessage($message, $struct->encoding);
                    }

    private function _decodeMessage($msg, $type){

        if($type == 0){
            return mb_convert_encoding($msg, "UTF-8", "auto");
        } elseif($type == 1){
            return imap_8bit($msg); //imap_utf8
        } elseif($type == 2){
            return imap_base64(imap_binary($msg));
        } elseif($type == 3){
            return imap_base64($msg);
        } elseif($type == 4){
            return imap_qprint($msg);
            //return quoted_printable_decode($msg);
        } else {
            return $msg;
        }
    }

The problem that I am having is some messages that are encoded with 7BIT are not being decoded correctly and I still see the messages encrypted when I print the $message

How can I correctly decode the messages when it's type is 7BIT?

Artjom B.
  • 61,146
  • 24
  • 125
  • 222
Jaylen
  • 39,043
  • 40
  • 128
  • 221
  • maybe this can help? http://stackoverflow.com/questions/12682208/parsing-email-body-with-7bit-content-transfer-encoding-php – Paolo Apr 02 '15 at 15:47
  • Er, 7-bit should mean it doesn't need any decoding. Can you please give a sample of the output you're seeing? – Max Apr 02 '15 at 16:13
  • Also, at no point was anything encrypted. Perhaps you meant encoded. – Max Apr 02 '15 at 16:13

0 Answers0