Mail-Klasse zum abholen der Mails über pop3

Jetzt hab ich das mail eine Mail über deine funktion anzeigen lassen.


Hier die Ausgabe
Code:
------_=_NextPart_001_00050D76.4281F9CF
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 7Bit
 
Das ist das Bild von einer Frau.
 
Da kannste mal gucken;-)
 
------_=_NextPart_001_00050D76.4281F9CF
Content-Type: text/html; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable
 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=3D"text/html; charset=3Dwindows-1252" http-equiv=3DContent-Type>
<META content=3D"MSHTML 5.00.3315.2870" name=3DGENERATOR></HEAD>
<BODY leftMargin=3D5 style=3D"COLOR: #000000; FONT: 10pt Courier New" topMargin=3D5>
<DIV>Das ist das Bild von einer <STRONG>Frau</STRONG>.</DIV>
<DIV>&nbsp;</DIV>
<DIV><EM>Da kannste mal gucken</EM>;-)</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV></BODY></HTML>
------_=_NextPart_001_00050D76.4281F9CF--
<<katrin_kl_cr.jpg>>


Und hier die email-Parts:
Code:
Array
(
	[0] => stdClass Object
		(
			[type] => 1
			[encoding] => 0
			[ifsubtype] => 1
			[subtype] => ALTERNATIVE
			[ifdescription] => 0
			[ifid] => 0
			[bytes] => 851
			[ifdisposition] => 0
			[ifdparameters] => 0
			[ifparameters] => 1
			[parameters] => Array
				(
					[0] => stdClass Object
						(
							[attribute] => BOUNDARY
							[value] => ----_=_NextPart_001_00050D76.4281F9CF
						)
 
				)
 
			[parts] => Array
				(
					[0] => stdClass Object
						(
							[type] => 0
							[encoding] => 0
							[ifsubtype] => 1
							[subtype] => PLAIN
							[ifdescription] => 0
							[ifid] => 0
							[lines] => 3
							[bytes] => 62
							[ifdisposition] => 0
							[ifdparameters] => 0
							[ifparameters] => 1
							[parameters] => Array
								(
									[0] => stdClass Object
										(
											[attribute] => CHARSET
											[value] => iso-8859-1
										)
 
								)
 
						)
 
					[1] => stdClass Object
						(
							[type] => 0
							[encoding] => 4
							[ifsubtype] => 1
							[subtype] => HTML
							[ifdescription] => 0
							[ifid] => 0
							[lines] => 9
							[bytes] => 487
							[ifdisposition] => 0
							[ifdparameters] => 0
							[ifparameters] => 1
							[parameters] => Array
								(
									[0] => stdClass Object
										(
											[attribute] => CHARSET
											[value] => iso-8859-1
										)
 
								)
 
						)
 
				)
 
		)
 
	[1] => stdClass Object
		(
			[type] => 3
			[encoding] => 3
			[ifsubtype] => 1
			[subtype] => OCTET-STREAM
			[ifdescription] => 0
			[ifid] => 0
			[bytes] => 105098
			[ifdisposition] => 0
			[ifdparameters] => 0
			[ifparameters] => 1
			[parameters] => Array
				(
					[0] => stdClass Object
						(
							[attribute] => NAME
							[value] => katrin_kl_cr.jpg
						)
 
				)
 
		)
 
)

Ich vermute mal, das das ALTERNATIVE sagt, ich kann Text ODER html anzeigen lassen. Das war nämlich eine mail, die ich mit Outlook in HTML geschrieben habe und ein Bild angehängt habe. Und jetzt habe ich drei Parts.
 
Genau. Bei multipart/alternative wird sowohl eine text-only-Variante als auch die HTML-Variante geschickt.
Dazu kommen dann halt noch die normalen Anhaenge.
 
Aber warum zeigt er mir dann diesen Header mit an?


------_=_NextPart_001_00050D76.4281F9CF
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 7Bit
.....
 
Ja, ich benutze noch dein Script. Hab aber
PHP:
print_r($struct->parts[$part]);
auskommentiert.
Das zeigt er eben auch nur bei den multipart/alternative - mails an.
 
Hmm. Scheint mir fast als haette ich mit multipart/alternative nicht so viel rumgetestet.

Ich werd mal gucken, dass ich was rumprobiere. Vielleicht find ich ja was.
 
Habe ein Proplem möchte meine Mails abrufen per PHP und möchte dan auch die Mails einzeln löschen wie mach ich dies.?
Den Code zum abrufen habe ich schon nur zum löschen nicht, könnt Ihr mir da helfen.

wie kann ich dan die einzelnen emails löschen
Code:
<? 


$boMail = new boMail("","","INBOX",""); 


//gibt alle nachrichten des Postfaches in ein Array: 
$overall=$boMail->getOverview();  


 


echo "<table border='1'><tr><td>Betreff</td><td>Datum</td><td>Absender</td><td>Aktion</td></tr>"; 
foreach ($overall as $key=>$val) { 
    echo "<tr><td><a href='$PHP_SELF?detail=$key'>".$overall[$key]['subject']."</a></td><td>".date("d.m.Y H:m",$overall[$key]['date'])."</td><td>".$overall[$key]['from']."</td><td><a href='$PHP_SELF?delete=$key'>Löschen</a></td></tr>"; 
} 
echo "</table><br>"; 


if ($detail) { 
    // Gibt den Message - Body mit Attachements zurück: 
    $msg=$boMail->getDetail($detail);  
} 
if ($delete){$msg=$boMail->getdelete($detail);}
// schließt Connection: 
$boMail->disconnect(); 


/* ------------------------------------------------------- 
    KLASSE boMail: 
*/ 
  
  
class boMail { 
      var $box;                 /** mailbox - Reverence             */ 
    var $mailbox;             /** Mailbox Host & Postfach         */ 
    var $user;              /** POP oder SMTP - user             */ 
    var $pw;                /** POP oder SMTP - password         */ 
    var $connected;         /** Is connected?                     */ 
    var $mailsnum;          /** Anzahl der Emails im postfach    */ 
    var $msgno;              /** Aktuelle msgno für detail        */ 
    var $mail=array();        /** mail - Details                    */ 
    var $isHTML=false;      /** ist HTML part vorhanden?        */ 
     
    var $types=array("text","multipart","message","application","audio","image","video","other"); 
    var $encodings=array("7BIT","8BIT","BINERY","BASE64","QUOTED-PRINTABLE","OTHER"); 


     


    function boMail( $user , $pw , $postfach="INBOX" , $host="localhost" , $port="imap:143") 
     { 
        $this->mailbox="{".$host."/".$port."}".$postfach; 
        $this->user=$user; 
        $this->pw=$pw; 
        return $this->connect(); 
     } 
      
      
       function connect() 
     { 
        if ($this->box = @imap_open( $this->mailbox , $this->user , $this->pw )) { 
            $this->connected=true; 
            $this->mailsnum = imap_num_msg($this->box); 
            return 1; 
        } else { 
            $this->echoError("Konnte keine Verbindung aufbauen!<br>".imap_last_error()); 
            return 0; 
           } 
     } 
      
     function disconnect() 
     { 
        if ($this->connected) { 
            imap_close($this->box); 
            $this->connected=fasle; 
        } 
     } 
      
      
     function getOverview() 
     { 
          
         if ($overview = imap_fetch_overview ($this->box,$this->mailsnum.":1")) { 
            foreach ($overview as $key=>$val) { 
                $head=imap_header($this->box,$val->msgno); 
                $ret[$val->msgno]["from"]=$head->fromaddress; 
                $elements=imap_mime_header_decode($head->subject); 
                for($i=0;$i<count($elements);$i++) { 
                       $subject=$elements[$i]->text; 
                } 
                $ret[$val->msgno]["subject"]=$subject; 
                $ret[$val->msgno]["date"]=$head->udate; 
                $ret[$val->msgno]["size"]=$val->size; 
                $flags=$head->Recent.$head->Unseen.$head->Answered.$head->Deleted.$head->Draft.$head->Flagged; 
                $ret[$val->msgno]["flags"]=$flags; 
                 
            } 
            return $ret; 
         }//<-if 
     } 
      
      
     function getDetail($msgno) 
     { 
         $this->msgno=$msgno; 
        $structure = imap_fetchstructure($this->box,$this->msgno); 
        $type=$this->types[$structure->type]; 
        $parts=$structure->parts; 
        $this->parseparts($parts,$type,$structure->subtype); 

         
     } 
      
   function getdelete($msgno)
   {
    $this->msgno=$msgno; 
        $structure = imap_delete($this->box,$this->msgno); 
        $type=$this->types[$structure->type]; 
        $parts=$structure->parts; 
      }  
     function parseparts($parts,$type,$subtype) 
    { 
        if (!empty($parts)) { 
              for ($i=(count($parts)-1);$i>=0;$i--) { 
                  if ($parts[$i]->parts) { 
                    $this->parseparts($parts[$i]->parts , $this->types[$parts[$i]->type] , $parts[$i]->subtype ); 
                  } 
                  $filename=$parts[$i]->parameters[0]->value; 
                $this->getPart($i+1 , $this->types[($parts[$i]->type)] , $parts[$i]->subtype , $this->encodings[$parts[$i]->encoding] , $filename); 
            } 
        } else { 
            $this->getPart(1 , $type , $subtype , $encoding); 
        } 
     

    } 
     
     
    function getPart($pid,$type,$subtype,$encoding,$filename="") 
    { 
        if (strtolower($subtype)=="html") $this->isHTML=1; 
        $body=imap_fetchbody($this->box,$this->msgno,$pid); 
        if ($encoding=="QUOTED-PRINTABLE" || empty($encoding)) $body=quoted_printable_decode($body); 
          if ($type=="text") { 
              if (strtolower($subtype)=="html") { 
                  echo html_entity_decode($body); 
              } else if (!$this->isHTML) { 
                   echo nl2br($body); //$this->mail['body'].= imap_fetchbody($this->box,$this->msgno,$pid); 
                   $this->isHTML=0; 
               } 
        } else if ($type=="image") { 
             echo "<br>BILD: <img src='".$this->mkAttachement($filename,$encoding,$body)."'>"; 
        } else if ($type=="application") { 
            $f=$this->mkAttachement($filename,$encoding,$body); 
             echo "<br>APPLICATION: <a href='$f'>$f</a>"; 
         } else { 
             echo "<B><I>Unbekanntes Format </i>$type/$subtype</b><br>"; 
        } 
    } 
      
      
     function mkAttachement($filename,$decode,$data) 
    { 
        $fh=fopen($filename,"w"); 
        if ($decode=="BASE64") $data=imap_base64($data); 
        fwrite($fh,$data); 
        fclose($fh); 
        return $filename; 
    } 
     

    function umlaute($text) 
    { 
        $text=imap_8bit($text); 
        $uml=array("=3DE4"=>"ä" , "=3DC4"=>"Ä" , "=3DFC"=>"ü" , "=3DDC"=>"Ü" , "=3DF6"=>"oe" , "=3DD6"=>"Ö" , "=3DDF"=>"ß" , "=3D20"=>" "); 
        foreach ($uml as $code=>$u) { 
              $text=str_replace($code,$u,$text); 
          } 
        return ($text); 
    } 

      
      function echoError($er) 
    { 
        echo "<div style='background:darkred;color:white'><b>$er</b></div>"; 
    } 
} 


?>

bitte den code korriegieren DANKESCHÖN
 
Zuletzt bearbeitet:
Willkommen in der tuts.de-Community

Erst einmal bitte ich dich deinen Post bzgl. der Rechtschreibung und Zeichensetztung zu korrigieren. Desweiteren: Packe den code bitte in PHP-BBs [code=php][/code] (zur besseren Lesbarkeit)
 

Neue Beiträge

Zurück