# \[How To\] Auto Expand mail folders using GreaseMonkey

**URL:** <https://help.nextcloud.com/t/how-to-auto-expand-mail-folders-using-greasemonkey/26768>\
**Category:** ℹ️ Support\
**Tags:** customisation, nc17, nc16, mail-app\
**Created:** [February 2, 2018, 1:44am UTC](https://help.nextcloud.com/t/how-to-auto-expand-mail-folders-using-greasemonkey/26768 "2018-02-02T01:44:44Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![dugite-code](https://help.nextcloud.com/user_avatar/help.nextcloud.com/dugite-code/32/6434_2.png) [@dugite-code](https://help.nextcloud.com/u/dugite-code)\
**Post date:** [February 2, 2018, 1:44am UTC](https://help.nextcloud.com/t/how-to-auto-expand-mail-folders-using-greasemonkey/26768/1 "2018-02-02T01:44:44Z")

</div>

\ ***Edit: Updated for Nextcloud 17 and mail v 0.18.1**  
Note: if you are using another language besides English you will have to change the text **Show all folders** and **Collapse folders**

I was sick of having to expand all my mail folders to avoid this bug:

> <https://github.com/nextcloud/mail/issues/659>
>
> Steps to reproduce
> Drag email from mail-message-list to expanded folder list with subfolders
> release
> Expected behaviour
> Mail is moved to correct folder and envelope icon...

So I wrote this quick user script to automatically expand all my folders.

Using the Latest Firefox Quantum you will need ~~Violent Monkey addon 2.8.27~~ ( [Latest Violent Mokey no longer works](https://github.com/violentmonkey/violentmonkey/issues/385#issuecomment-378472515) Greasemonkey 4.3 however now works ) or greater, Open the Violent monkey dashboard and click the + sign to add a new script.

Past the following code, changing the `yourdomain.tld` to your domain:

```
// ==UserScript==
// @name Nextcloud Mail Expand folders
// @namespace https://yourdomain.tld/
// @include https://yourdomain.tld/apps/mail/*
// @require https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js
// @require https://gist.github.com/raw/2625891/waitForKeyElements.js
// @version 1
// @grant NEXTCLOUDMAIL
// ==/UserScript==

/* Paste Here */

this.$ = this.jQuery = jQuery.noConflict(true);

console.log('[NMEF] - Waiting');
waitForKeyElements ("span:contains('Show all folders')", expandALL, true);
waitForKeyElements ("span:contains('Collapse folders')", setTimeout(expandINDIV, 2000), true);

function expandALL() {
  console.log('[NMEF] - Expand ALL Folders');
  $("span:contains('Show all folders')")[0].click();
};

function expandINDIV() {
  console.log('[NMEF] - Expand individual Folders');
  $('li[class*="app-navigation-entry--collapsible"] > button').click();
}

```

**Note:** this loads the remote content jquery and waitForKeyElements.js, if you wish to have them bound locally open the `// @require` links and past the contents at the `/* Paste Here */` line. Then just delete the lines:

```
// @require https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js
// @require https://gist.github.com/raw/2625891/waitForKeyElements.js
```

---

<div class="post-metadata">

**Author:** ![dugite-code](https://help.nextcloud.com/user_avatar/help.nextcloud.com/dugite-code/32/6434_2.png) [@dugite-code](https://help.nextcloud.com/u/dugite-code)\
**Post date:** [January 29, 2019, 7:25am UTC](https://help.nextcloud.com/t/how-to-auto-expand-mail-folders-using-greasemonkey/26768/2 "2019-01-29T07:25:31Z")

</div>

Currently still working well on Firefox 64.0.2 with Nexcloud 15

---

<div class="post-metadata">

**Author:** ![dugite-code](https://help.nextcloud.com/user_avatar/help.nextcloud.com/dugite-code/32/6434_2.png) [@dugite-code](https://help.nextcloud.com/u/dugite-code)\
**Post date:** [May 9, 2019, 8:56am UTC](https://help.nextcloud.com/t/how-to-auto-expand-mail-folders-using-greasemonkey/26768/3 "2019-05-09T08:56:54Z")

</div>

Updated for Nextcloud 16

---

<div class="post-metadata">

**Author:** ![dugite-code](https://help.nextcloud.com/user_avatar/help.nextcloud.com/dugite-code/32/6434_2.png) [@dugite-code](https://help.nextcloud.com/u/dugite-code)\
**Post date:** [November 7, 2019, 7:36am UTC](https://help.nextcloud.com/t/how-to-auto-expand-mail-folders-using-greasemonkey/26768/4 "2019-11-07T07:36:44Z")

</div>

Updated for Nextcloud 17

---

<div class="post-metadata">

**Author:** ![wwe](https://help.nextcloud.com/user_avatar/help.nextcloud.com/wwe/32/72963_2.png) [@wwe](https://help.nextcloud.com/u/wwe)\
**Post date:** [December 3, 2024, 9:16pm UTC](https://help.nextcloud.com/t/how-to-auto-expand-mail-folders-using-greasemonkey/26768/5 "2024-12-03T21:16:59Z")

</div>



---

<div class="post-metadata">

**Author:** ![wwe](https://help.nextcloud.com/user_avatar/help.nextcloud.com/wwe/32/72963_2.png) [@wwe](https://help.nextcloud.com/u/wwe)\
**Post date:** [December 9, 2024, 2:09pm UTC](https://help.nextcloud.com/t/how-to-auto-expand-mail-folders-using-greasemonkey/26768/6 "2024-12-09T14:09:32Z")

</div>



---

<div class="post-metadata">

**Author:** ![tneneh](https://help.nextcloud.com/letter_avatar/tneneh/32/6_22734026db12803ebb3e059622ac3534.png) [@tneneh](https://help.nextcloud.com/u/tneneh)\
**Post date:** [June 7, 2025, 4:37pm UTC](https://help.nextcloud.com/t/how-to-auto-expand-mail-folders-using-greasemonkey/26768/7 "2025-06-07T16:37:22Z")

</div>

The following is a Greasemonkey script for expanding all mail folders automatically when opening Nextcloud Mail in Firefox. This is an update for [[How To] Auto Expand mail folders using GreaseMonkey](https://help.nextcloud.com/t/how-to-auto-expand-mail-folders-using-greasemonkey/26768) which works with Nextcloud 31.

In Firefox install the add-on: [Greasemonkey – Get this Extension for 🦊 Firefox (en-US)](https://addons.mozilla.org/en-US/firefox/addon/greasemonkey/)

Then in the Greasemonkey addon create a new script and paste the script below.

**ATTENTION:**

- Make sure to replace [cloud.example.com](http://cloud.example.com) in the lines starting with @namespace and @include with your Nextcloud domain
- Replace the text ‘Alle abonnierten Postfächer anzeigen’ with the English, French, Spanish, etc. text that you click in Nextcloud Mail to expand all of your subscribed folders. It needs to be exactly the text that the button shows, probably sth. like ‘Show all subscribed mailboxes’ in English.

```auto
// ==UserScript==
// @name Nextcloud Mail: Expand all folders
// @namespace https://cloud.example.com/
// @include https://cloud.example.com/apps/mail/*
// @require https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js
// @require https://gist.githubusercontent.com/BrockA/2625891/raw/waitForKeyElements.js
// @version 1
// @grant none
// ==/UserScript==

this.$ = this.jQuery = jQuery.noConflict(true);

waitForKeyElements(
  'span.app-navigation-entry__name:contains("Alle abonnierten Postfächer anzeigen")',
  function(elem) {
    console.log('[NC Mail Expander] Click expand button', elem);
    elem.click();
  },
  true
);

```

A polite request to the Nextcloud Mail developers: Please allow users to display exactly the mail folders they want when opening Nextcloud Mail as it can also get very messy when having multiple mailboxes. An example for a feature request in this regard is: [Collapse mailboxes to 1 line each with display of unread messages from the inbox · Issue #9300 · nextcloud/mail · GitHub](https://github.com/nextcloud/mail/issues/9300)
