title: PHP Notice: Undefined property: stdClass::$disposition
body: <p>Question No. 1 - can anybody tell me whats wrong with the code?? I have a script getting only the pdf file....</p>
  
  <p>Question No. 2 - is there a way get the username and password in another php file like this;</p>
  
  <pre><code>define("Email", "xxxxx.com");
  define("Password", "******");
  </code></pre>
  
  <p>how can I do thAT?? please prefer to the code below.  </p>
  
  <pre><code>&lt;?php
  $hostname = '{imap.gmail.com:993/imap/ssl}INBOX';
  $username = 'xxxxx@gmail.com';
  $password = '*******';
  $savedirpath = "/Attachment";
  $type = 'ReadAttachment';
  $obj = new $type;
  $obj-&gt;getdata($hostname ,$username ,$password,$savedirpath);
  class ReadAttachment
  {
      function getdecodevalue($message,$coding) {
          switch($coding) {
              case 0:
              case 1:
                  $message = imap_8bit($message);
                  break;
              case 2:
                  $message = imap_binary($message);
                  break;
              case 3:
              case 5:
                  $message=imap_base64($message);
                  break;
              case 4:
                  $message = imap_qprint($message);
                  break;
          }
          return $message;
      }
  
  
      function getdata($hostname ,$username ,$password,$savedirpath) {
  
          $savedirpath = str_replace('\\', '/', $savedirpath);
          if (substr($savedirpath, strlen($savedirpath) - 1) != '/') {
              $savedirpath .= '/';
          }
          $mbox = imap_open ($hostname , $username , $password) or die("can't connect: " . imap_last_error());
          $message = array();
          $message["attachment"]["type"][0] = "text";
          $message["attachment"]["type"][1] = "multipart";
          $message["attachment"]["type"][2] = "message";
          $message["attachment"]["type"][3] = "application";
          $message["attachment"]["type"][4] = "audio";
          $message["attachment"]["type"][5] = "image";
          $message["attachment"]["type"][6] = "video";
          $message["attachment"]["type"][7] = "other";
  
                  $MC = imap_check($mbox);
                  $result = imap_fetch_overview($mbox,"1:{$MC-&gt;Nmsgs}",0);
                  $jk = 1;
                  foreach ($result as $overview) {
  
                      $subj = $overview-&gt;subject;
                      $date= strtotime($overview-&gt;date);
                      $unixDate = date("YmdHis", $date);
                      $email= $overview-&gt;from;
                          $opening = strpos($email, '&lt;')+1;         //   removed username of a sender
                          $closing = strpos($email, '&gt;');           //   removed username of a sender
                      $from = substr($email, $opening, $closing-$opening);
  
  
  
  
                          $structure = imap_fetchstructure($mbox, $jk);                                 //, FT_UID - for pop3   
                          $parts = (isset($structure-&gt;parts) ? $structure-&gt;parts : false);
                          $fpos=2;
  
                          for($i = 1; $i &lt; count($parts); $i++) {
  
                              $message["pid"][$i] = ($i);
                              $part = $parts[$i];
  
                              if($part-&gt;disposition == "ATTACHMENT") {    
  
                                  $message["type"][$i] = $message["attachment"]["type"][$part-&gt;type] . "/" . strtolower($part-&gt;subtype);
                                  $message["subtype"][$i] = strtolower($part-&gt;subtype);
                                  $ext=$part-&gt;subtype;
                                  $params = $part-&gt;dparameters;
                                  $filename=$part-&gt;dparameters[0]-&gt;value;
                                  $mege="";
                                  $data="";
                                  $mege = imap_fetchbody($mbox,$jk,$fpos);  
                                  $filename="$filename";
                                  $extension=pathinfo($filename);
  
                                  $file_extension = $extension['extension'];
                                  if($file_extension === "pdf")
                                  {
                                      $new_filename = $subject . "*" . $from . "*" . "$unixDate" . ".pdf";
                                      $fp=fopen($savedirpath.$new_filename,'w');
                                      $data=$this-&gt;getdecodevalue($mege,$part-&gt;type); 
                                      fputs($fp,$data);
                                      fclose($fp);
                                      $fpos+=1;                                   
                                  }
                              }                   
                          } imap_delete($mbox,$jk);
                      $jk++;              
  
                  }       
  
              imap_expunge($mbox);
              imap_errors();
              imap_close($mbox);
  
  
  }
  }
  
  ?&gt;
  </code></pre>