\documentclass{article}
\usepackage{ulem}
\usepackage{graphicx}
\usepackage{hyperref}
\pagestyle{headings}
\begin{document}
Since IMP 6.1.0 this can be configured in imp/config/backends.local.php.

After scouring Google for several days looking for a solution to this common question, and after subtle prodding on the Imp mailing list, I decided to roll my own method of making IMP create the default sent, trash, drafts, and spam folders as defined in "horde/imp/config/prefs.php" the first time a user logs in.   This code was written for IMP 4.1.x. This code does not work with IMP 4.2.x.

What we need to do is create a Maintenance Task in IMP similar to the default "tos\_agreement" task.  The first thing we need to do is create a maintenance task.  This is done by creating a PHP script called "horde/imp/lib/Maintenance/Tasks/create\_default\_folders.php" which contains the following class:

<pre><code class="language-php">
<?php
class Maintenance\_Task\_create\_default\_folders extends Maintenance\_Task \{
    function doMaintenance() \{
        global \$prefs;
        require\_once IMP\_BASE . '/lib/Folder.php';
        \$imp\_folder = \&IMP\_Folder::singleton();
        \$folder\_options = array(
            'sent\_mail\_folder', 'drafts\_folder', 'trash\_folder', 'spam\_folder'
        );
        foreach (\$folder\_options as \$this\_folder) \{
            \$folder = \$prefs->getValue(\$this\_folder, true);
            if (\$folder) \{
                \$folder = IMP::folderPref(\$folder, true);
                if (!\$imp\_folder->exists(\$folder)) \{
                    \$imp\_folder->create(\$folder, true);
                \}
            \}
        \}
        return true;
    \}
    function describeMaintenance() \{
        return \_("This process makes sure the default folders are created on your account.");
    \}
\}
</code></pre>
Now you'll need to edit "horde/imp/lib/Maintenance/imp.php" to reflect this change:

<pre><code class="language-php">
     var \$maint\_tasks = array(
        'tos\_agreement'              => MAINTENANCE\_FIRST\_LOGIN,
        'create\_default\_folders'     => MAINTENANCE\_FIRST\_LOGIN,
// If you have users who often "accidently" delete their folders, you can do this instead:
//      'create\_default\_folders'     => MAINTENANCE\_EVERY,
        'fetchmail\_login'            => MAINTENANCE\_EVERY,
        'rename\_sentmail\_monthly'    => MAINTENANCE\_MONTHLY,
        'delete\_sentmail\_monthly'    => MAINTENANCE\_MONTHLY,
        'delete\_attachments\_monthly' => MAINTENANCE\_MONTHLY,
        'purge\_trash'                => MAINTENANCE\_MONTHLY
    );
</code></pre>
Finally, add a preference in "horde/imp/config/prefs.php" like this:

<pre><code class="language-php">
    \$\_prefs['create\_default\_folders'] = array(
        'value' => 1,
        'locked' => false,
        'shared' => false,
        'type' => 'implicit');
</code></pre>
\end{document}
