Roundcube Community Forum

Third Party Contributions => API Based Plugins => Topic started by: luislopez on May 07, 2013, 01:46:17 PM

Title: I'm begginer and need a hand, please.
Post by: luislopez on May 07, 2013, 01:46:17 PM
NOTE: I speak spanish and it's too hard to me write in english... sorry!

I need to write a plugin. This plugin must parse a mail subject and puts a link or a button to open another website. this link/button should be inserted in the mailbox list and in the preview header.

I'm reading a lot of pages and a lot of code, but I can't write something that works... Any suggestion?

Thanks in advence!

--
Luis
Title: Re: I'm begginer and need a hand, please.
Post by: SKaero on May 07, 2013, 05:42:56 PM
Take a look at the message_headers_output hook http://trac.roundcube.net/wiki/Plugin_Hooks#Taskmail and read the plugin documentation http://trac.roundcube.net/wiki/Doc_Plugins
Title: Re: I'm begginer and need a hand, please.
Post by: luislopez on May 08, 2013, 12:35:18 PM
I really appreciate your help.

I wrote a tiny pluggin and it's working now! But I have a little problem:
When I add a new header, it's not displayed if the 'larry' skin is in use, but if you're using the 'clasic' skin the header is displayed  :o

Any idea?  :D
Title: Re: I'm begginer and need a hand, please.
Post by: SKaero on May 08, 2013, 03:03:39 PM
What your code?
Title: Re: I'm begginer and need a hand, please.
Post by: luislopez on May 09, 2013, 07:52:10 AM
This is my plugin... I'm a php beginner too    ;D


<?php

class myFirstPlugin extends rcube_plugin
{
public $task 'mail';

function init()
{
$rcmail rcmail::get_instance();
if (!$rcmail->action || in_array($rcmail->action, array('list''show''preview')))
$this->add_hook'message_headers_output' , array($this'addHeaders') );
}

function addHeaders$p )
{
$rcmail rcmail::get_instance();
$link "";
$LEcode $this->parseCode( (string)$p['output']['subject']['value'] );
if ( isset ( $LEcode['opEcod'] ) && isset( $LEcode['opType'] ) && isset ( $LEcode['opID'] ) && isset($LEcode['opCK']) )
{
$start fmod(floatval($LEcode['opEcod'] . $LEcode['opType'] . $LEcode['opID']), 23);
if ( $validator substr'GMYXTRWABHLCNJZSQVFPDKE' $start ) )
{
if ( $validator == $LEcode['opCK'] )
{
$link $this->createLink'http://google.com/' 'Open op.: ' $LEcode['opID'] , 'Click to visit op. ' $LEcode['opID'] );

//  Here I add the new header that is showed if clasic skin is in use
$p['output']['MyPlugin'] =  array('title' => 'Open Op.''value' => $link'html' => true) ;
}
}
}
return $p;
}


function parseCode $code )
{
$code strtoupper$code );
$regex '|.*OPERATION\.(?P<opEcod>[0-9]+)\.(?P<opType>[0-9]+)\.(?P<opID>[0-9]+)\.(?P<opCK>[A-Z]).*|i';
preg_match$regex $code $LEarray );
if ( !isset( $LEarray ) )
$LEarray null;
return ( $LEarray );
}

function createLink $href$text$title )
{
$a html::a( array( 'href' => $href 'target' => '_blank' 'title' => $title )  ,  $text );
    return($a);
}
}


Many thanks!  :D
Title: Re: I'm begginer and need a hand, please.
Post by: luislopez on May 15, 2013, 12:43:37 PM
HI!  ;D

I solved the problem writing a plugin to add a new button in the toolbar. It solves the skin problem...

Please, close this topic  :)