Author Topic: Making a string containing user's folders [Plugin]  (Read 4720 times)

Offline Lambda89

  • Jr. Member
  • **
  • Posts: 10
Making a string containing user's folders [Plugin]
« on: April 15, 2010, 05:21:28 AM »
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

    Offline JohnDoh

    • Global Moderator
    • Hero Member
    • *****
    • Posts: 2,845
    Making a string containing user's folders [Plugin]
    « Reply #1 on: April 15, 2010, 08:32:35 AM »
    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ā€¦

    Offline Lambda89

    • Jr. Member
    • **
    • Posts: 10
    Making a string containing user's folders [Plugin]
    « Reply #2 on: April 15, 2010, 08:41:32 AM »
    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. :/

    Offline Lambda89

    • Jr. Member
    • **
    • Posts: 10
    Making a string containing user's folders [Plugin]
    « Reply #3 on: April 15, 2010, 04:25:10 PM »
    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.