6.0.0-git
2018-12-12
Last Modified 2013-10-11 by Jan Schneider

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:

<?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.");
    }
}

Now you'll need to edit "horde/imp/lib/Maintenance/imp.php" to reflect this change:

     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
    );

Finally, add a preference in "horde/imp/config/prefs.php" like this:

    $_prefs['create_default_folders'] = array(
        'value' => 1,
        'locked' => false,
        'shared' => false,
        'type' => 'implicit');