Author Topic: Server Error when using messages_list hook  (Read 3121 times)

Offline nuclearping

  • Newbie
  • *
  • Posts: 5
Server Error when using messages_list hook
« 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:
Code: [Select]
<?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:



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! :)
« Last Edit: February 22, 2013, 04:55:59 PM by nuclearping »

Offline nuclearping

  • Newbie
  • *
  • Posts: 5
Re: Server Error when using messages_list hook
« Reply #1 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.

Code: [Select]
    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. :)