Author Topic: Get Message-Id when message is displayed  (Read 24 times)

Offline ibb-koeln

  • Newbie
  • *
  • Posts: 1
Get Message-Id when message is displayed
« on: Today at 07:02:46 AM »

I'm totally new to Roundcube, so maybe its a noob question...

I would like to get the message-id as well as the imap uid for a mail when it is displayed to the user. I need to store these data to be able to link to a certain message from another software, ideally by opening roundcube directly showing this mail. 

I already wrote a simple plugin

Code: [Select]
class my_plugin extends rcube_plugin {
    public $task = 'mail';
    var $message_id = "no-id";
    var $message = 0;
    function init() {
        $this->add_hook('message_load', array($this, 'message_load'));
        $this->register_action('plugin.get_data', array($this, 'request_data'));
    function request_data() {
        $rcmail = rcmail::get_instance();
        $rcmail->output->command('plugin.my_plugin_callback', array('result' => "OK", 'message_id' => $this->message_id));
    function message_load($args) {
        $this->message_id = "message_load_called"; // "$args['object']->get_header( 'message-id', false);

Code: [Select]
if( rcmail.env.action=='preview') {
    rcmail.addEventListener('init', function(evt) {
        rcmail.addEventListener('plugin.my_plugin_callback', receive_data);
        rcmail.http_get('plugin.get_data', '', false);

function receive_data(response) {

The callback loop http_get()/receive_data() is working fine, but I never get a result for message-id, it's always the initial "no-id" as if message_load() is not called. Any hints on that?

Btw, is there any doc for the javascript rcmail object available? I already found the stuff on github (plugin/skin API) and the PHP-Documentation but nothing about the javascript object.


Offline SKaero

  • Administrator
  • Hero Member
  • *****
  • Posts: 5,493
Re: Get Message-Id when message is displayed
« Reply #1 on: Today at 04:33:16 PM »
What your doing doesn't work because PHP doesn't retain state between requests. What that means is when Roundcube make a request to get a message the "message_load" function would be called and "$this->message_id" would be set. But when you make the request to "plugin.my_plugin_callback" its a brand new request that doesn't have access to the data from the prior request.

What you may try and do is use the "set_env" function in the "message_load" load function to set the values you want into the JS object "rcmail.env" For example:
Code: [Select]
    function message_load($args) {
        $rc = rcube::get_instance();
        $rc->output->set_env('message_id', "message_load_called");