Welcome Guest, Not a member yet? Register   Sign In
Email issue
#1

[eluser]stuffradio[/eluser]
Ok, I almost have this working!

Code:
<?php

            ######################################

            #Coded By Jijo Last Update Date[Jan/19/06]

            #####################################




            ##########################################################


            ###################### Class readattachment ###############
class Readattachment
{
var $username;
var $encrypted;
var $pic;
var $time;
var $url;
var $caption;
var $tag;


     function Readattachment()
     {
       $this->CI=& get_instance();

     }
    
     function checkExists($username, $password)
     {
       $query = $this->CI->db->get_where('project_users', array('username' => $username, 'password' => $password));
       if ($query->num_rows() > 0)
       {
         return true;
       } else {
         return false;
       }
     }


     function checkAndUpload($arg, $pic)
     {

preg_match("#username: ([a-zA-Z0-9]+)#i",$arg,$username);
$username = $username[1];
preg_match("#password: ([a-zA-Z0-9]+)#i",$arg,$password);
$password = $password[1];
$encrypted = md5($password);

      if (checkExists($username, $encrypted))
      {
        uploadData($username, $encrypted, $pic, time(), '', 'Default Caption', 'nsfw');
      } else {

      }
     }


        function getdecodevalue($message,$coding)
        {
        if ($coding == 0)
        {
           $message = imap_8bit($message);
        }
        elseif ($coding == 1)
        {
          $message = imap_8bit($message);
        }
        elseif ($coding == 2)
        {
           $message = imap_binary($message);
        }
        elseif ($coding == 3)
        {
       $message=imap_base64($message);
       }
        elseif ($coding == 4)
        {
           $message = imap_qprint($message);
        }
        elseif ($coding == 5)
        {
         $message = imap_base64($message);
        }
        return $message;
        }

            function getdata($host,$login,$password,$savedirpath)
            {
$mbox = imap_open ($host,  $login, $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";
        
         for ($jk = 1; $jk <= imap_num_msg($mbox); $jk++)
         {
        $headerinfo = imap_header($mbox, $jk);

        $subject = $headerinfo->Subject;
                        $matches = array();
                        if (preg_match('/^=\?[^?]*\?B\?(.*)\?=/m', $subject, $matches))
                                $subject = base64_decode($matches[1]);

         $structure = imap_fetchstructure($mbox, $jk , FT_UID);  
         $parts = $structure->parts;
         $fpos=1;
    for($i = 0; $i < count($parts); $i++)
{
                  $message["pid"][$i] = ($i);
                  $part = $parts[$i];
if ($part->type == 0) {
        $fpos+=1;
        continue;
    }


                  if(TRUE)
                     {
                      
                      $message["type"][$i] = $message["attachment"]["type"][$part->type] . "/" . strtolower($part->subtype);
                     $message["subtype"][$i] = strtolower($part->subtype);
                     $ext=$part->subtype;
                if ($part->ifdparameters)
                  foreach($part->dparameters as $dparam)
                    if (strtolower($dparam->attribute) == 'filename') $filename = $dparam->value;
                if (empty($filename))
                  if ($part->ifparameters)
                    foreach($part->parameters as $param)
                      if (strtolower($param->attribute) == 'name') $filename = $param->value;

if (empty($filename) && $part->ifid)
        $filename = trim($part->id, '<>');
          

     if (empty($filename)) $filename = 'nfn' . rand() . '.' . strtolower($part->subtype);



                               $mege="";
                           $data="";
                             $mege = imap_fetchbody($mbox,$jk,$fpos);
                             $body = imap_fetchbody($mbox, $jk, '1');
                           checkAndUpload($body, $filename);
                           $fp=fopen($savedirpath . $filename,w);
                           $data=$this->getdecodevalue($mege,$part->type);
                           fputs($fp,$data);
                           fclose($fp);
                           $fpos+=1;


                     } else {

                     }

               }
         imap_delete($mbox,$jk);
         }
         imap_expunge($mbox);
         imap_close($mbox);
         }
        
            }

  function uploadData($username, $encrypted, $pic, $time, $url, $caption, $tag)
  {
        $this->CI->db->insert('pb_photos', array('time' => time(), 'pic' => $this->CI->upload->file_name, 'url' => base_url() . 'system/application/views/uploads/', 'caption' => $caption, 'poster' => $username, 'tag' => $tag));
}
?&gt;


The main parts you need to check are:

Code:
function uploadData($username, $encrypted, $pic, $time, $url, $caption, $tag)
  {
        $this->CI->db->insert('pb_photos', array('time' => time(), 'pic' => $this->CI->upload->file_name, 'url' => base_url() . 'system/application/views/uploads/', 'caption' => $caption, 'poster' => $username, 'tag' => $tag));
}


Continued below....
#2

[eluser]stuffradio[/eluser]
Continued

Code:
function checkAndUpload($arg, $pic)
     {

preg_match("#username: ([a-zA-Z0-9]+)#i",$arg,$username);
$username = $username[1];
preg_match("#password: ([a-zA-Z0-9]+)#i",$arg,$password);
$password = $password[1];
$encrypted = md5($password);

      if (checkExists($username, $encrypted))
      {
        uploadData($username, $encrypted, $pic, time(), '', 'Default Caption', 'nsfw');
      } else {

      }
     }

Code:
$body = imap_fetchbody($mbox, $jk, '1');
                           checkAndUpload($body, $filename);


Why do you think it's not inserting in to the db? Everything should return true.
#3

[eluser]Derek Allard[/eluser]
One way to work your way through db queries that don't work is to put immediately after the query
Code:
die($this->db->last_query()); // or $this->CI->db->last_query() in your case
and manually inspect the sql created.
#4

[eluser]stuffradio[/eluser]
Thanks, got it working!

Btw, any ideas why it won't delete and expunge the emails?
#5

[eluser]Derek Allard[/eluser]
What was it? An SQL error? Share so others can learn!

With respect to the imap functions, I don't know. May be worth contacting your webhost.
#6

[eluser]stuffradio[/eluser]
When using internal functions you have to go:

Code:
$this->functionName()

Also, I had to remove the if statement and I dealt with whether or not it was true from within the functions. If it's false, then you just tell it to die.

Took me a while to figure those things out Tongue




Theme © iAndrew 2016 - Forum software by © MyBB