Jump to content

imap_fetchsructure() error


bhavya

Recommended Posts

<html>

<head>

<script language="php">

  function show_mails($server, $account, $password)

  {

    $mailbox = imap_open("{".$server.":995/pop3/ssl}INBOX", $account, $password);

    $mails = imap_fetch_overview($mailbox,"1:*", FT_UID); // This is fetching an overview of all emails

 

    // Output as a table:

    $return = '<table width="100%">

                <tr>

                  <td><b>#</b></td>

                  <td><b>From</b></td>

                  <td><b>Date / Time</b></td>

                  <td><b>Subject</b></td>

                </tr>';

    $size = count($mails); // Number of messages

    $cmsg = 0; // This is used to have a continously number

    for($i=$size-1;$i>=0;$i--)

    {

      $cmsg++;

      $value = $mails[$i];

      $return .= '<tr><td>'.$cmsg.'</td><td>'.$value->from.'</td><td>'.$value->date.'</td><td><a href="'.$_SERVER['PHP_SELF'].'?id='.$value->msgno.'">'.$value->subject.'</a></td></tr>';

    }

    $return .= '</table>';

echo $return;

 

 

$attachments = array();

$message_number=$size-1;

    $structure = imap_fetchstructure($mailbox, $message_number);

 

    if(isset($structure->parts) && count($structure->parts)) {

 

        for($i = 0; $i < count($structure->parts); $i++) {

 

            $attachments[$i] = array(

                'is_attachment' => false,

                'filename' => '',

                'name' => '',

                'attachment' => ''

            );

         

            if($structure->parts[$i]->ifdparameters) {

                foreach($structure->parts[$i]->dparameters as $object) {

                    if(strtolower($object->attribute) == 'filename') {

                        $attachments[$i]['is_attachment'] = true;

                        $attachments[$i]['filename'] = $object->value;

                    }

                }

            }

         

            if($structure->parts[$i]->ifparameters) {

                foreach($structure->parts[$i]->parameters as $object) {

                    if(strtolower($object->attribute) == 'name') {

                        $attachments[$i]['is_attachment'] = true;

                        $attachments[$i]['name'] = $object->value;

                    }

                }

            }

         

            if($attachments[$i]['is_attachment']) {

                $attachments[$i]['attachment'] = imap_fetchbody($mailbox, $message_number, $i+1);

                if($structure->parts[$i]->encoding == 3) { // 3 = BASE64

                    $attachments[$i]['attachment'] = base64_decode($attachments[$i]['attachment']);

                }

                elseif($structure->parts[$i]->encoding == 4) { // 4 = QUOTED-PRINTABLE

                    $attachments[$i]['attachment'] = quoted_printable_decode($attachments[$i]['attachment']);

                }

            }

         

        }

     

    }

 

    return $attachments;

    imap_close($mailbox);

  }

   

  function show_mail($id, $server, $account, $password)

  {

    $mailbox = imap_open("{".$server.":995/pop3}INBOX", $account, $password);

    $mail = imap_body($mailbox,$id, FT_UID);

    // This is fetching the email..

    $mail = htmlentities(stripslashes($mail));

    /* stripslashes is stripping the slashes, htmlentities transforms all of the non-regular symbols to their equal html code expression. */

    $return = '<pre>'.$mail.'</pre>';

    imap_close($mailbox);

    return $return;

  }

 

  if(isset($_POST['id']))

    if(is_numeric($_GET['id']))

      echo show_mail($_GET['id'], "pop.gmail.com", "[email protected]", "sphoorthi04");

    else

      echo 'wrong parameter';

  else

      echo show_mails("pop.gmail.com", "[email protected]", "sphoorthi04");

 

</script></head>

</html>

 

 

plz find the attached output screen shot.

output must display the inbox and body of the msg must be viewable.can anyone please help.

 

[attachment deleted by admin]

Link to comment
https://forums.phpfreaks.com/topic/185898-imap_fetchsructure-error/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.