Расшифровка вложения

  • Автор темы champion
  • Дата начала

champion

Guest
РАсшифровка вложения

Люди глючит скрипт вложений (чтение почты)
вот код:
PHP:
<?
$mailbox="{pop3.spaceweb.ru/pop3:110}INBOX";
$domain="elabuga-city.ru";
$pop_domain="pop3.spaceweb.ru";
$langs="ru";
$template="default";
$title="webrik-mail";
$prefix="elabuga-city.ru+";
$read=$_GET['id'];
$login="elabuga-city.ru+test";
$password="test";
$pop_domain="pop.elabuga-city.ru";
$imap=imap_open("{".$pop_domain."/pop3:110}INBOX",$login,$password) or die ("<font face=verdana size=1 color=red><b><center>?????????? ??????????? ? ????????</center></b></font></td></tr><tr><td><img src=images/bottom.gif></td></tr></table></body>");
$m=imap_body($imap,$read);
preg_match("'[\s]{4}(.*)[\s]'si", $m, $Match);
preg_match("'Content-type.*?\".*?\"'si",$Match[0],$type);
//print_r($type);
preg_match("'Content-Disposition.*?\".*?\"'si",$Match[0],$typ);
header($type[0]);
header($typ[0]);
$Match[0]=preg_replace("'Content.*?\"'siU","",$Match[0]);
preg_match("%[\s]{4}(.*)[\s]%si", $Match[0], $M);
echo base64_decode($M[1]);
?>
Заголовки, все замечательно, а вложение не видать
 

AHTIXPICT

Новичок
У imap есть специальные ф-ии что бы получить все вложения
imap_fetchbody()
 

champion

Guest
В таком случае я взял код прямо c php.net, но не пашет
PHP:
 $struct = imap_fetchstructure($mbox, $mid);
       
       $parts = $struct->parts;
       $i = 0;

       if (!$parts) { /* Simple message, only 1 piece */
         $attachment = array(); /* No attachments */
         $content = imap_body($mbox, $mid);
       } else { /* Complicated message, multiple parts */
       
         $endwhile = false;
       
         $stack = array(); /* Stack while parsing message */
         $content = "";    /* Content of message */
         $attachment = array(); /* Attachments */
       
         while (!$endwhile) {
           if (!$parts[$i]) {
             if (count($stack) > 0) {
               $parts = $stack[count($stack)-1]["p"];
               $i    = $stack[count($stack)-1]["i"] + 1;
               array_pop($stack);
             } else {
               $endwhile = true;
             }
           }
         
           if (!$endwhile) {
             /* Create message part first (example '1.2.3') */
             $partstring = "";
             foreach ($stack as $s) {
               $partstring .= ($s["i"]+1) . ".";
             }
             $partstring .= ($i+1);
           
             if (strtoupper($parts[$i]->disposition) == "ATTACHMENT") { /* Attachment */
               $attachment[] = array("filename" => $parts[$i]->parameters[0]->value,
                                     "filedata" => imap_fetchbody($mbox, $mid, $partstring));
             } elseif (strtoupper($parts[$i]->subtype) == "PLAIN") { /* Message */
               $content .= imap_fetchbody($mbox, $mid, $partstring);
             }
           }

           if ($parts[$i]->parts) {
             $stack[] = array("p" => $parts, "i" => $i);
             $parts = $parts[$i]->parts;
             $i = 0;
           } else {
             $i++;
           }
         } /* while */
       } /* complicated message */

       echo "Analyzed message $mid, result: <br />";
       echo "Content: $content<br /><br />";
       echo "Attachments:"; print_r ($attachment);
Выдает:
Notice: Undefined property: disposition in z:\home\localhost\www\attach.php on line 50

Notice: Undefined property: parts in z:\home\localhost\www\attach.php on line 58

Notice: Undefined property: parts in z:\home\localhost\www\attach.php on line 58

Notice: Undefined offset: 2 in z:\home\localhost\www\attach.php on line 32

Notice: Undefined offset: 2 in z:\home\localhost\www\attach.php on line 58
Analyzed message 1, result:
Content:

Attachments:Array ( )


-~{}~ 02.04.05 19:02:

???

-~{}~ 03.04.05 08:14:

Неужели тут никто не может мне помочь?
 

champion

Guest
Ещё раз, вот код:
PHP:
<?
$domain="elabuga-city.ru";
$pop_domain="pop3.spaceweb.ru";
$read=$_GET['id'];
$mid=$read;
$login="elabuga-city.ru+test";
$password="test";
$pop_domain="pop.elabuga-city.ru";
$mbox=imap_open("{".$pop_domain."/pop3:110}INBOX",$login,$password) or die ("<font face=verdana size=1 color=red><b><center>?????????? ??????????? ? ????????</center></b></font></td></tr><tr><td><img src=images/bottom.gif></td></tr></table></body>");
$struct = imap_fetchstructure($mbox, $mid);

       $parts = $struct->parts;
       $i = 0;

       if (!$parts) { /* Simple message, only 1 piece */
         $attachment = array(); /* No attachments */
         $content = imap_body($mbox, $mid);
       } else { /* Complicated message, multiple parts */

         $endwhile = false;

         $stack = array(); /* Stack while parsing message */
         $content = "";    /* Content of message */
         $attachment = array(); /* Attachments */

         while (!$endwhile) {
           if (!$parts[$i]) {
             if (count($stack) > 0) {
               $parts = $stack[count($stack)-1]["p"];
               $i    = $stack[count($stack)-1]["i"] + 1;
               array_pop($stack);
             } else {
               $endwhile = true;
             }
           }

           if (!$endwhile) {
             /* Create message part first (example '1.2.3') */
             $partstring = "";
             foreach ($stack as $s) {
               $partstring .= ($s["i"]+1) . ".";
             }
             $partstring .= ($i+1);

             if (strtoupper($parts[$i]->disposition) == "ATTACHMENT") { /* Attachment */
               $attachment[] = array("filename" => $parts[$i]->parameters[0]->value,
                                     "filedata" => imap_fetchbody($mbox, $mid, $partstring));
             } elseif (strtoupper($parts[$i]->subtype) == "PLAIN") { /* Message */
               $content .= imap_fetchbody($mbox, $mid, $partstring);
             }
           }

           if ($parts[$i]->parts) {
             $stack[] = array("p" => $parts, "i" => $i);
             $parts = $parts[$i]->parts;
             $i = 0;
           } else {
             $i++;
           }
         } /* while */
       } /* complicated message */

       echo "Analyzed message $mid, result: <br />";
       echo "Content: $content<br /><br />";
       echo "Attachments:"; print_r ($attachment);
?>
Но не пашет! Выдаются такие сообщения:

Notice: Undefined property: disposition in z:\home\localhost\www\create.php on line 45

Notice: Undefined property: parts in z:\home\localhost\www\create.php on line 53

Notice: Undefined property: parts in z:\home\localhost\www\create.php on line 53

Notice: Undefined offset: 2 in z:\home\localhost\www\create.php on line 27

Notice: Undefined offset: 2 in z:\home\localhost\www\create.php on line 53
Analyzed message 1, result:
Content:

Attachments:Array ( )
 

3BEP

Новичок
Еще раз: тело письма (главное все заголовки - есть ли там вообще ATTACHMENT, есть ли заголовок Content-Disposition. Thunderbird например может воткнуть Content-Disposition: inline;) Ну и значения переменных на разных этапах выполнения программы, например значение $parts[$i] в
if (strtoupper($parts[$i]->disposition) == "ATTACHMENT") { /* Attachment */
 
Сверху