imap_fetchbody und charset

Goltergaul

Well-known member
ID: 17553
L
26 April 2006
480
7
Hi ich hole mir mit imap_fetchbody() den body von einer email und bekomme folgendes zurück: Guten Abend alle zusammen, hier die Anf=E4nge

Eigentlich sollte das "Guten Abend alle zusammen, hier die Anfänge" heißen....

Was ist das und wie kann ich das konvertieren?

thx für jeden Tipp =)
 
sorry 4 doppelpost.

ich habe jetzt mal diese funktionen übernommen und etwas erweitert. ich habe jetzt folgendes:

PHP:
$return[$header->Msgno]['body'] = imap_fetchbody($this->stream, $header->Msgno,1.1,FT_PEEK);
$return[$header->Msgno]['body']=$this->checkbody($return[$header->Msgno]['body'],$struct);


function checkbody($body,$struct)
	{
	    global $mailbox;
	    if ($struct->subtype!='PLAIN')
	        {
	        	if ($struct->parts[0]->encoding==3)
	                {
	                    $body=base64_decode($body);
	                }
	            if ($struct->parts[0]->encoding==4)
	                {
	                    $body=quoted_printable_decode($body);
	                }
				foreach($struct->parts[0]->parameters as $params) {
					if($params->attribute == "CHARSET")
						$charset=$params->value;
				}
				$body=htmlentities($body, ENT_COMPAT, $charset);
	        }
	    else
	        {
	            if ($struct->encoding==3)
	                {
	                    $body=base64_decode($body);
	                }
	            if ($struct->encoding==4)
	                {
	                    $body=quoted_printable_decode($body);
	                }
				foreach($struct->parameters as $params) {
					if($params->attribute == "CHARSET")
						$charset=$params->value;
				}
				$body=htmlentities($body, ENT_COMPAT, $charset);
	        }
	    return $body;
	}

Das funktioniert soweit ganz gut. Bis auf eine mail die ich habe, wo der korrekte body in section 1.1 zu sein scheint. bei allen anderen emails ist er in section 1

With an email message that only has a text body and does not have any mime attachments, imap-fetchbody() will return the following for each requested part number:

(empty) - Entire message
0 - Message header
1 - Body text

With an email message that is a multi-part message in MIME format, and contains the message text in plain text and HTML, and has a file.ext attachment, imap-fetchbody() will return something like the following for each requested part number:

(empty) - Entire message
0 - Message header
1 - MULTIPART/ALTERNATIVE
1.1 - TEXT/PLAIN
1.2 - TEXT/HTML
2 - file.ext

Wie kann ich denn jetzt bevor ich imapt_fetchbody machen herausfinden ob ich ein MULTIPART habe oder nicht um die richtige section zu wählen? imap_fetchstructure scheint mir da auch nicht so recht helfen zu wollen?