Author Topic: Simple question  (Read 3870 times)

Offline Aven3000

  • Newbie
  • *
  • Posts: 9
Simple question
« on: June 17, 2013, 07:46:58 PM »
Hello all,

It's a very simple question but I can't find the answer anywhere. I found a plugin that returns the number of unread messages. It is located in plugins/getunread/getunread.php. My question is how do I output it? I just wanted a file that outputs that number, that's it.

Thank you

Offline SKaero

  • Administrator
  • Hero Member
  • *****
  • Posts: 5,543
    • http://SKaero.com/
Re: Simple question
« Reply #1 on: June 17, 2013, 08:53:12 PM »
Where are you trying to output it?

Offline Aven3000

  • Newbie
  • *
  • Posts: 9
Re: Simple question
« Reply #2 on: June 18, 2013, 10:43:31 AM »
The plugin returns the number of unread messages.

So I'm trying to output the number of unread messages. So in other words, how do I get the plugin results? where do I 'echo' the results?

Thank you

Offline Aven3000

  • Newbie
  • *
  • Posts: 9
Re: Simple question
« Reply #3 on: June 18, 2013, 01:45:33 PM »
Sorry I misread your message.

I'd prefer to output it in just its own separate page. A blank white page. 

But if that's not possible then at least on the main Email page.

Thank you

Offline SKaero

  • Administrator
  • Hero Member
  • *****
  • Posts: 5,543
    • http://SKaero.com/
Re: Simple question
« Reply #4 on: June 18, 2013, 02:01:48 PM »
Can you post the code in the plugin?

Offline Aven3000

  • Newbie
  • *
  • Posts: 9
Re: Simple question
« Reply #5 on: June 18, 2013, 02:20:06 PM »
Here it is:

Code: [Select]
class test extends rcube_plugin{
    public $task='mail';

    function init(){     
       $this->register_handler('plugin.unreadmessage',array($this, 'unreadmessage_handler'));
    }
    function unreadmessage_handler(){
       $rcmail = rcmail::get_instance();       
       $count=$rcmail->imap->messagecount('INBOX', 'UNSEEN');
       return $count   
    }
}

Offline Aven3000

  • Newbie
  • *
  • Posts: 9
Re: Simple question
« Reply #6 on: June 18, 2013, 06:43:10 PM »
Btw this is an issue that I've been trying to figure out for at least 12 hours now. I just want to get that number, that's it. Preferably displayed in a file by itself.

Offline SKaero

  • Administrator
  • Hero Member
  • *****
  • Posts: 5,543
    • http://SKaero.com/
Re: Simple question
« Reply #7 on: June 18, 2013, 07:47:40 PM »
The following code should work:
Code: [Select]
class test extends rcube_plugin{
    public $task='mail';

    function init(){     
       $this->register_action('plugin.unreadmessage', array($this, 'unreadmessage_handler'));
    }
    function unreadmessage_handler(){
       $rcmail = rcmail::get_instance();       
       $count=$rcmail->imap->messagecount('INBOX', 'UNSEEN');
       die($count)   
    }
}

The URL would be <RC URL>?_task=mail&_action=plugin.unreadmessage

Offline Aven3000

  • Newbie
  • *
  • Posts: 9
Re: Simple question
« Reply #8 on: June 19, 2013, 12:17:31 PM »
Okay thank you I think we're close. However, when I go to that page, it says "SERVICE CURRENTLY NOT AVAILABLE!"

I have three questions:

1) The plugin folder is called 'getunread' so in my plugins/main.inc.php, I have this code:
Code: [Select]
$rcmail_config['plugins'] = array('getunread');
And without it, the mail page goes blank, it breaks.  So I'm guessing I'm on the right track if I leave the code there correct?

2) The die() makes the mail page die as well. I'm guessing because I put the plugin as part of 'mail' task?

3) If I remove die() and just replace it with return or echo, it still gives "SERVICE CURRENTLY NOT AVAILABLE!" and I used the URL http://websiteURL/roundcube/?_task=mail&_action=plugin.unreadmessage

Thank you

Offline Aven3000

  • Newbie
  • *
  • Posts: 9
Re: Simple question
« Reply #9 on: June 19, 2013, 12:35:55 PM »
And here's error in the log:

Code: [Select]
[19-Jun-2013 09:34:06 -0700]: PHP Error: No handler found for action plugin.unreadmessage in /var/www/roundcube/program/include/rcube_plugin_api.php on line 324 (GET /roundcube/?_task=mail&_action=plugin.unreadmessage)

Offline SKaero

  • Administrator
  • Hero Member
  • *****
  • Posts: 5,543
    • http://SKaero.com/
Re: Simple question
« Reply #10 on: June 19, 2013, 01:36:55 PM »
If the folder name is getunread the class name also needs to be getunread.

Offline Aven3000

  • Newbie
  • *
  • Posts: 9
Re: Simple question
« Reply #11 on: June 19, 2013, 02:12:28 PM »
Okay thank you that fixed most of the problems.

This is my code:
Code: [Select]
class getunread extends rcube_plugin{
    public $task='mail';

    function init(){     
       $this->register_action('plugin.unreadmessage', array($this, 'unreadmessage_handler'));
    }
    function unreadmessage_handler(){
       $rcmail = rcmail::get_instance();       
       $count=$rcmail->imap->messagecount('INBOX', 'UNSEEN');
       die($count);
    }
}

However, the page is just blank. And it didn't break the page because I was able to write some stuff after.

Offline SKaero

  • Administrator
  • Hero Member
  • *****
  • Posts: 5,543
    • http://SKaero.com/
Re: Simple question
« Reply #12 on: June 20, 2013, 08:20:00 AM »
Then if I had to guess the code to get the number of unread messages is wrong, I haven't played with it before so I can't say for sure.