is it possible to create a moblog with CI

#11
[eluser]andreagam[/eluser]
Thanks, Carlton

I found the library and gave it a try, but still can't grab anything from the mail server...
I tried from gmail (BTW, it's required an SSL Host?) as well as from "ordinary" mail servers, but still get only errors.

I'll keep on trying in my spare time.

Bye, Andrea

#12
[eluser]Carlton[/eluser]
I had a quick try too, but with no success...I will give it another shot at lunch time.
I am pretty sure you need to have this running on a server with SSL..getting that up and running on an existing server is another task in itself Sad

#13
[eluser]Carlton[/eluser]
Using the example on the imap_pop class page the following code doesn't appear to execute correctly
<code>$this->imap_pop->connect_and_count($config);</code>
It was because my PHP installation didn't have support for the imap libary so went into php.ini and removed the comment (Wink from the line
<code>extension=php_imap.dll</code>

Now I just get this error
<code>A PHP Error was encountered

Severity: Warning

Message: imap_open() [function.imap-open]: Couldn't open stream {pop.gmail.com:995/pop3/ssl/novalidate-cert}INBOX

Filename: libraries/imap_pop.php

Line Number: 102
</code>

Is this the same one you get Andrea?

#14
[eluser]sophistry[/eluser]
if you post the code and errors, maybe someone could help?

best idea is to strip it down to the minimal code - even hard coding a single imap_open() call to make sure that you've got a valid POP server listening to you. the class doesn't really help you debug your POP or imap connections it just makes it easier to connect once you've got them working.

like raymondm did a few posts ago, just use these two raw imap functions:
Code:
// this is just about the simplest email setup to enable you a test that the POP server works
// open the connection
$mbox =  imap_open ("{mail.bluebottle.com:110/pop3}INBOX", "user", "pass")or die("can't connect: " . imap_last_error());
//show the number of messages
print_r(imap_num_msg($mbox));

#15
[eluser]Sally D[/eluser]
mob.php heres my library function it returns the emails into an array as of now only images I don't know what do yet for for videos

next thing is to add this array into a database and then mark these messages as seen


and then down load the files after putting array info in database for later retrieval file_put_contents is the next thing I want to do


Code:
&lt;?php

if (!defined('BASEPATH')) exit ('No direct script access allowed');

class Mob {


    var $conn;
        var $user;
        var $pass;
    var $mbox;
        
    

        function Mob($params)
        {
            $this->conn = $params['conn'];
                $this->user = $params['user'];
                $this->pass = $params['pass'];
            $this->mbox = imap_open($this->conn,$this->user,$this->pass) or die("could not connect");
            
        }

      

        function get_email()
        {
        $headers = imap_headers($this->mbox);
                $numEmails = sizeOf($headers);
                
                $emails = array();
              
                for($i = 1; $i <= $numEmails; $i++)
                {
                    $structure = imap_fetchstructure($this->mbox, $i);
                        $mailHeader = imap_headerinfo($this->mbox,$i);
                        $emails['from'][$i][] = $mailHeader->fromaddress;
                        $emails['subject'][$i][] = strip_tags($mailHeader->subject);
                        $emails['date'][$i][] = $mailHeader->date;
                      
                          
                       if($structure->subtype === 'MIXED')
                       {
                           $part = 1;
                        for($k = 0; $k < count($structure->parts); $k++ )
                                 {
                                     if($structure->parts[$k]->encoding === 1)
                                        {
                                            $emails['body'][$i][] = imap_fetchbody($this->mbox, $i, $part);
                                              
                                        }
                                        else if($structure->parts[$k]->encoding === 3)
                                        {
                                            $emails['atts'][$i][] = imap_base64(imap_fetchbody($this->mbox, $i, $part));
                             }
                                      $part++;
                            }




                       }
                       else
                       {
                $emails['body'][$i][] = imap_body($this->mbox, $i);
                       }
                      $emails['emailId'][$i][] = $i;
                        
               }
            
               return $emails;
      
        }

        

}
?&gt;


controller moblog

Code:
&lt;?php

class Moblog extends Controller {


    function Moblog()
    {
        parent::Controller();
                $params = array("conn"=>"{mail.bluebottle.com/pop3:110}INBOX",
                                "user"=>"\m",
                                "pass"=>"r\6");
                $this->load->library('mob',$params);
        
        
        
              
    }
    
    function index()
    {
        
              
                $emails = $this->mob->get_email();
                echo "<pre>";
                print_r($emails);
                echo "</pre>";
                
              
              
    }
    
            
        
}
?&gt;


I hit delete

#16
[eluser]sophistry[/eluser]
nice work raymondm! you've got a cool thing going there. you've got a nice specific shell of code that's lean and mean and does exactly what you want it to do, nothing more nothing less. it's all up front and easy to read. after noodling on it for many weeks, my class has gotten a little bit out of hand and could probably suffer a refactor. but, it does what i need it to do -

eventually i hope my imap_pop library can benefit from any advances you make! including advances in code clarity.

cheers. i look forward to the next installment.

#17
[eluser]Sally D[/eluser]
sophistry


I got a question about your class. its about your coding style. You used a dynamic variable in your code something like this

array_push( $$key, $arr );

a dynamic variable takes the value of the variable and makes it into a variable right.

can you can explain to me why you did it this way. it's baffling to me when I read it. Maybe if you told me why I can learn to use them in situtions where it can be of benifit.

#18
[eluser]sophistry[/eluser]
mostly i avoid variable variables because the result in baffling code (as you noted). also, it's a general rule of thumb of mine that if you think "i'll use variable variables" that really means that you probably need another class in the design and you need to handle the operation via properties.

that said, sometimes i'll use them in a pinch. and this little section of code you called out is kind of like a little stubby embryonic class. in this case, the code is looping over an array of objects building an array or arrays that needs the keys and they need to stay in sync and get filled with values from the array that is being looped. that's pretty much the only valid use for variable variables in my book.

i'll step back a bit to give this operation some context.

when a variable is not set and you try to use it, PHP issues a warning. you can suppress those warnings or make sure they don't happen by always having variables set when you try to use them.

this array (up a few lines from the foreach in question) lists all the variables we want to have set so that PHP doesn't complain:
Code:
$address_keys_we_need_to_be_set = explode(' ', 'from to cc bcc reply_to sender return_path');
those correspond to the header object returned by the imap_headerinfo() function in this:
Code:
$header_obj=imap_headerinfo($this->IMAP_resource, $this->msg_id);

so, this code checks whether the address keys are in the header object. it looks for those keys (from to cc bcc reply_to sender return_path).
if the key is in the object then an empty array is created in a new variable named for the key (this first use of variable variable).

Code:
$$key = array();

so, now we have a variable that holds an empty array. the variable is called $from (assuming this is the first iteration of the foreach)
then, another foreach starts because the header_obj has a nested array that holds more objects.
the code makes the object into an array and stacks it up onto $arr
the personal part of the address (if any) is decoded (this is a bit of a loose hack here since there could be other encodings)

then, finally (to your question), the array ($arr) that we just pulled out the the header object is pushed onto the array named $from (assuming first iteration or more generally $$key) so $from ends up with a nested array of arrays instead of a nested array of objects.

the whole thing is really just reorganizing the header_obj to make it easier to use. there is probably a slew of fat that could be trimmed from this beast! but, it works and gets you a nice tidy array of arrays instead of mixed objects and arrays. i don't like objects with no classes (the PHP std object) because i don't know how to manipulate the data inside them. i'd like to learn if there is a way to manipulate (get and set) std object properties, but right now i just turn them into arrays.

Code:
// turn each of the arrays of objects into arrays of arrays
    // with each address part getting encoding
    foreach ($address_keys_we_need_to_be_set as $key)
    {    
        // make sure the array item is set
        if (isset($header_obj->$key))
        {
            // it's there,
            // variable is named for the key
            $$key = array();
            $arr = array();
            foreach ($header_obj->$key as $obj)
            {
                // coerce it to an array
                $arr[] = (array)$obj;
                //p($key);
                //p($arr);
                // take the personal part and apply decoding
                if (isset($arr['personal']))
                {
                    $arr['personal'] = $this->decode_mime_text($arr['personal']);
                }
                
                // push the array onto the array
                array_push( $$key, $arr );
            }
            $email_arrays_array[$key] = $arr;
            //p($$key);
        }
        
    }


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.