Roundcube Community Forum

Third Party Contributions => API Based Plugins => Topic started by: nuclearping on February 22, 2013, 10:23:01 AM

Title: Server Error when using messages_list hook
Post by: nuclearping on February 22, 2013, 10:23:01 AM
Hey there,

I'm new to RoundCube plugin development. We're using RC version 0.8.5.

I wrote a little plugin to get used to and experiment with the system.

Now I'm stuck with the messages_list hook.

Example code:
<?php

class my_plugin_test extends rcube_plugin {

    function 
init() {
        
// ...
        
$this->add_hook('messages_list', array($this'parse_messages'));
    }

    function 
parse_messages($arg) {              

        
// Server Error
        //var_dump($arg);

/*
        // Works
        $v = $arg['messages'];
        // ... but now Server Error
        var_dump($v);
*/

        // Server Error
        
foreach($arg['messages'] as $message) {
            
var_dump($message);
        }

        return 
$arg;
    }

    
// ...
}

?>


As soon as I try to access the contents of the $arg-array I get a "Server Error! (OK)" message:

(http://img542.imageshack.us/img542/8131/rcservererror.jpg)

I'm stuck at this for quite a while and can't find any solution.  :o

When I remove any contents of the function and just keep "return $args" it works normally. But as soon as I try to do anything with the $args-array I get this error message.

What am I doing wrong?

Thanks for your help! :)
Title: Re: Server Error when using messages_list hook
Post by: nuclearping on February 22, 2013, 07:03:25 PM
Ok, I think I got it. Stupid me.  ::)

It seems that I cannot send any output at that position.

    function parse_messages($arg) {             
        ob_start();
        $f = fopen("/var/www/roundcubemail-0.8.5/temp/test.txt", "w");
        foreach($arg['messages'] as $message) {
            var_dump($message);
            $x = ob_get_clean();
            fputs($f, $x . "\n");
        }
        fclose($f);
        ob_end_clean();
       
        return $arg;
    }


Seems to do the trick. :)