Roundcube Community Forum

 

Making a string containing user's folders [Plugin]

Started by Lambda89, April 15, 2010, 05:21:28 AM

Previous topic - Next topic

Lambda89

Hi guys and girls. Still writing a plugin ...

This time, I'm trying to create a string containing HTML
  • -elements based on the user's subscribed mailboxes, which should then be placed in a via JavaScript.

    My code:

    $rcmail = rcmail::get_instance();
          
    $mailboxes = $rcmail->imap->list_mailboxes();
          
    foreach ($mailboxes as $key => $folder) {
            $folders .= "
  • ".$folder."
  • ";
    }

    This generates a server-error, however, and sadly I'm too much of a beginner to understand how I should solve it.

    Grateful for all assistance

    JohnDoh

    Hi, I have also run into this once or twice and I found that you had to do it differently depending on where in the system you are doing it. If your plugin is called as part of the 'mail' then you can use the "render_mailboxlist" hook, this will pass to your function an array with the a list of the mailboxes in. If you are doing it else where, say as part of a settings panel then I think you can use the method you are already trying.
    Roundcube Plugins: Contextmenu, SpamAssassin Prefs, and more...

    Lambda89

    Good to know. I'm in settings, messing around.

    My only concern now is why it generates a server-error. From what I can understand, the return value of the list_mailboxes() should be an array of the names. :/

    Lambda89

    Problem fixed. The solution was to call the imap_init-function, from the rcmail-instance.

    Like this:

    $rcmail = rcmail::get_instance();

    $rcmail->imap_init(); //This piece of code does the trick

    Then, as previously stated, getting the object, looping it to create the string, then returning it to the JavaScript. Feels really simple now in hindsight.