Welcome Guest, Not a member yet? Register   Sign In
Uninitialized string offset: 0
#1

[eluser]stuffradio[/eluser]
I'm getting this error when I'm trying to use the imap pop class.

http://codeigniter.com/wiki/imap_pop_class/

I am using the modified version.

Quote:A PHP Error was encountered

Severity: Notice

Message: Uninitialized string offset: 0

Filename: libraries/imap_pop.php

Line Number: 92
A PHP Error was encountered

Severity: Notice

Message: Uninitialized string offset: 0

Filename: libraries/imap_pop.php

Line Number: 93

A PHP Error was encountered

Severity: Notice

Message: Uninitialized string offset: 0

Filename: libraries/imap_pop.php

Line Number: 94
A PHP Error was encountered

Severity: Notice

Message: Uninitialized string offset: 0

Filename: libraries/imap_pop.php

Line Number: 96
A PHP Error was encountered

Severity: Notice

Message: Uninitialized string offset: 0

Filename: libraries/imap_pop.php

Line Number: 97
A PHP Error was encountered

Severity: Notice

Message: Undefined variable: email_array

Filename: libraries/imap_pop.php

Line Number: 330
A PHP Error was encountered

Severity: Notice

Message: Unknown: Can't open mailbox {}: invalid remote specification (errflg=2)

Filename: Unknown

Line Number: 0


Any ideas?
#2

[eluser]Matthieu Fauveau[/eluser]
Seems like the $init_array is empty from a quick look on the class code. However I'm not using it so I can't be of much help...
#3

[eluser]sophistry[/eluser]
@stuff

thanks for trying the imap_pop class.
most of those are notices, not errors. PHP is crying about unintialized variables.

that last error shows that the init code you are sending the class is not working to find the proper mailbox.

why don't you post some of your code rather than just error messages? also, use code blocks not quote blocks to make code easier to read.
#4

[eluser]stuffradio[/eluser]
Sorry it took so long to reply.

I am constantly getting the warning:

Quote:A PHP Error was encountered

Severity: Warning

Message: imap_open() [function.imap-open]: Couldn't open stream {}

Filename: libraries/imap_pop.php

Line Number: 103

Also the error message:
Quote:Array ( [0] => Can't open mailbox {}: invalid remote specification )


Here is the code:
Code:
<?php

class Email extends Controller
{

  function Email()
  {
    parent::Controller();
    $this->load->library('imap_pop', '');
  }
  
  function index()
  {
    
    $config['server'] = 'pop.gmail.com:993';
    $config['login'] = 'xxxxxxx';
    $config['pass'] = 'xxxxx';
    $config['service_flags'] = '/imap/ssl';
    $config['mailbox'] = 'INBOX';
    $msg_count = $this->imap_pop->connect_and_count($config);
    $this->imap_pop->set_IMAP_attachment_dir("http://localhost/system/application/views/uploads/email/");
    //$em = $this->imap_pop->grab_email_as_array_and_store(20);
    echo $this->imap_pop->count_messages();
    $this->imap_pop->close();
    //print_r($em);

  }

}
#5

[eluser]sophistry[/eluser]
@stuffradio - as far as i know those functions should work with imap rather than pop, but i don't use them for imap. that may be part of the issue.

can you connect to your imap server with the imap functions (take the imap_pop lib out of the picture)?

what does this code give you (found at php.net):
Code:
$mbox = imap_open ("{imap.gmail.com:993/imap/ssl}INBOX", "[email protected]", "password")
     or die("can't connect: " . imap_last_error());

also, there may be a problem with ssl if your PHP has no ssl support built in.

since you are in uncharted waters using the imap account, please refer to this php page and let us know what you find:

http://www.php.net/manual/en/function.imap-open.php
#6

[eluser]stuffradio[/eluser]
This is the error:

Quote:can't connect: Can't open mailbox imap.gmail.com:995/imap/ssl}INBOX: no such mailbox

Note: That it has to be port 995 because that's the imap port. I was just trying port 993 at the time because I was seeing if I could get it to work in other ways, and forgot to change the port back. It still produces the same error message though.
#7

[eluser]sophistry[/eluser]
http://mail.google.com/support/bin/answe...swer=78799 that's not what this google page says... port 993 is the one to use for IMAP.

not sure if this is incidental but there is a curly brace missing from the error message posted. probably a forum thing...

anyway, the error you see says "no such mailbox"... so it seems to be connecting and getting to imap.

here's code that i used (with the imap_pop lib) to connect to google gmail IMAP:
Code:
$config['server']='imap.gmail.com:993';
        $config['login']='[email protected]';
        $config['pass']='mypassword';
        $config['service_flags'] = '/imap/ssl/novalidate-cert';
        $config['mailbox']='INBOX';
#8

[eluser]stuffradio[/eluser]
Yeah well I've gotten a lot further now. I've taken the class found on phpclasses called readattachment class. I can now get the image file, and successfully download it to a folder.

I don't know why it only does it once, I want it to do it everytime even if I don't delete the email for testing purposes. What I'm stuck on now is getting the subject, and the message.

I'm working on making it do a match case of the username database. This is the format I'm going for:

To: [email protected]
From: Doesn't matter
Subject: <username here>

Message:
Username: <username>
Password: <password> (Will be encrypted and checked in the database)

Photo caption: This is a caption

EndMessage;

It will then, as it is uploading the file upload the info in the database. Do you have any suggestions? This is what I have so far.

Code:
&lt;?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 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);
                           $fp=fopen($savedirpath . $filename,w);
                           $data=$this->getdecodevalue($mege,$part->type);
                          
                           fputs($fp,$data);
                           fclose($fp);
                           // I was thinking of putting uploadData here                          
                           $fpos+=1;

                          
                     }
        
               }
         //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;
#9

[eluser]sophistry[/eluser]
gmail is weird about the way it marks messages as read. so, the message won't be downloaded again. my advice is send a bunch of emails.




Theme © iAndrew 2016 - Forum software by © MyBB