Hello everyone,
I've been using RC for years and now need to develop a plug-in for a customer.
My plug-in opens a second window when a message is previewed or replied to. In both cases the URL of the new window refers to an external software which provides additional info to a given message ID.
I already solved opening the second window after the right events.
How to retrieve the message ID?
way of identifying messages. I need to "translate" that to the global message ID which can be used by external software.
seems to be passed by the "id" parameter in the URL for the compositor. I find it even more difficult to retrieve the original message's ID here.
I already spent some time listening to the right events and opening the 2nd window which is now working. Hopefully you'll be able to give me some hints how to get the message IDs.
Kind regards Daniel Böhmer
On 04/18/2013 12:42 PM, Daniel Böhmer wrote:
- When a message is previewed I already get its UID which seems to be RC's own
way of identifying messages. I need to "translate" that to the global message ID which can be used by external software.
You need IMAP's message sequence identifier or Message-ID header?
Hi,
- When a message is previewed I already get its UID which seems to be RC's
own way of identifying messages. I need to "translate" that to the global message ID which can be used by external software.
You need IMAP's message sequence identifier or Message-ID header?
The message ID as found in the header of the message.
Daniel
On 04/18/2013 01:09 PM, Daniel Böhmer wrote:
The message ID as found in the header of the message.
in plugin init():
$this->add_hook('message_headers_output', array($this, 'headers'));
and headers() method could look like:
function headers($args) { $rcmail = rcube::get_instance(); $rcmail->output->set_env('messageid', $args['headers']->get('message-id')); }
and now in javascript you can use rcmail.env.messageid variable.
Hi,
thanks for your code snippet. I am pretty sure the hook is being called because when I made a typo I got an error message that the method get() could not be called on a non-object. It seems to me that this is a runtime error and thus the hook method must have been called.
and now in javascript you can use rcmail.env.messageid variable.
Unfortunately I don't find this attribute in the rcmail.env object. I inspect it with Firebug. I also tried to add another variable with a static string just in case the result of the function is undefined or something alike. However I cannot get any additional attribute into rcmail.env.
public $task = 'mail';
function init() {
// include our files
$this->include_script('my_plugin.js');
$this->include_stylesheet('my_plugin.css');
// register hook for message headers being processed
$this->add_hook('message_headers_output', array($this, 'headers'));
}
// provide message ID from message header function headers($args) { $rcmail = rcube::get_instance();
// BOTH NOT VISIBLE
$rcmail->output->set_env('foo', 'bar');
$rcmail->output->set_env('messageid', $args['headers']->get('message-
id'));
// DOCUMENTATION SAYS method for this hook shall return the
// (possibly modified) output argument
return $args['output'];
}
I only know the list of available hooks found at [1]. Can you point me at documentation for $rcmail->output->set_env or $args['headers']. I cannot find it.
Daniel
On 04/18/2013 02:21 PM, Daniel Böhmer wrote:
thanks for your code snippet. I am pretty sure the hook is being called because when I made a typo I got an error message that the method get() could not be called on a non-object. It seems to me that this is a runtime error and thus the hook method must have been called.
What Roundcube version?
What Roundcube version?
Current 0.9 with no plug-in except the one I'm writing.
Just updated yesterday.
On 04/18/2013 02:28 PM, Daniel Böhmer wrote:
What Roundcube version?
Current 0.9 with no plug-in except the one I'm writing.
Then, works for me. How (and when) do you access rcmail.env.messageid. Open the source of the page and search for "messageid" string it should be there.
Hi,
Then, works for me. How (and when) do you access rcmail.env.messageid. Open the source of the page and search for "messageid" string it should be there.
The "when" got me: In the message list view I can use the "init" hook and during the runtime of this function the rcmail.env.messageid is available. The 2nd window opens and displays the message ID. Great!
Unfortunately the PHP hook isn't called when a message is being replied to. I proved that by dumping the message ID to STDERR in PHP and watching the Apache error log. Do you have any idea what to do in this case?
Daniel
On 04/18/2013 03:18 PM, Daniel Böhmer wrote:
The "when" got me: In the message list view I can use the "init" hook and during the runtime of this function the rcmail.env.messageid is available. The 2nd window opens and displays the message ID. Great!
Unfortunately the PHP hook isn't called when a message is being replied to. I
You need to use message_compose hook. There in $args['param'] you'll have 'draft_uid', 'reply_uid', 'forward_uid' and 'uid' depending on action used (edit-draft, reply, forward, edit-as-new). The folder will be in $args['param']['mbox']. Having this information you'll need to create rcube_message object to get the message headers (or use rcube_imap methods). After all you should save your message-id in $args['message-id'] - it will be stored in session.
Hi,
this is how I got it partly working:
##################################################### function init() { $this->add_hook('message_headers_output', array($this, 'headers')); }
function compose($args) {
// retrieve RC's UID
$reply_uid = $args['param']['reply_uid'];
if($reply_uid) {
// we are going to reply to some e-mail
// fetch header block
$rcube = rcube::get_instance();
$storage = $rcube->get_storage();
$header = $storage->get_raw_headers($reply_uid);
/* doesn't work:
$header = $storage->get_message_header($uid);
$message_id = $header->get('message-id');
*/
// try to "parse"
$matches = preg_match('/Message-I[dD]: (.+)/', $header,
$message_ids);
if($matches == 1) {
$args['message-id'] = $message_ids[0];
error_log("replying to " . $args['message-id']);
}
}
}
#############################################
As you see in the comment you suggested solution with calling get() doesn't work for me. I always got values like "mid:12345" with 12345 being a random(?) number, probably another ID for that e-mail.
Using the raw header I am able to get the original message ID.
Unfortunately I don't find the value from $args['message-id'] with JavaScript. Where should it be?
I am not really happy with "parsing" the mail header on my own. Any suggestions why get('message-id') doesn't work?
Daniel Böhmer
On 04/22/2013 10:25 PM, Daniel Böhmer wrote:
Hi,
this is how I got it partly working:
##################################################### function init() { $this->add_hook('message_headers_output', array($this, 'headers')); }
function compose($args) { // retrieve RC's UID $reply_uid = $args['param']['reply_uid']; if($reply_uid) { // we are going to reply to some e-mail // fetch header block $rcube = rcube::get_instance(); $storage = $rcube->get_storage(); $header = $storage->get_raw_headers($reply_uid); /* doesn't work: $header = $storage->get_message_header($uid);
^^^^^^^
should be $reply_uid
Unfortunately I don't find the value from $args['message-id'] with JavaScript. Where should it be?
As I said, it will be stored in session, because on compose (on reply) there's a redirect sent. You need to read this value after redirect and use set_env() to make it available in javascript on compose page.
There's no good hook for this, so I propose to add such code in plugin init() method:
$rcmail = rcube::get_instance(); if ($rcmail->task == 'mail' && $rcmail->action == 'compose') { $ID = get_input_value('_id', RCUBE_INPUT_GET); if ($ID && ($COMPOSE = $_SESSION['compose_data_'.$ID])) { $rcmail->output->set_env('messageid', $COMPOSE['message-id']); } }
or sth like that.