function store_email_into_folder($msg, $folder = 'SentFromDolibarr')
{
    global $user, $db;
    $mailboxconfig = new Usermailboxconfig($db);
    $mailboxconfig->fetch_from_user($user->id);
    $user->mailbox_imap_login = $mailboxconfig->mailbox_imap_login;
    $user->mailbox_imap_password = $mailboxconfig->mailbox_imap_password;
    $user->mailbox_imap_host = $mailboxconfig->mailbox_imap_host;
    $user->mailbox_imap_port = $mailboxconfig->mailbox_imap_port;
    $user->mailbox_imap_ssl = $mailboxconfig->mailbox_imap_ssl;
    $user->mailbox_imap_ssl_novalidate_cert = $mailboxconfig->mailbox_imap_ssl_novalidate_cert;
    $user->mailbox_imap_ref = $mailboxconfig->get_ref();
    $user->mailbox_imap_connector_url = $mailboxconfig->get_connector_url();
    $mbox = imap_open($user->mailbox_imap_connector_url . $folder, $user->mailbox_imap_login, $user->mailbox_imap_password);
    $check = imap_check($mbox);
    $before = $check->Nmsgs;
    $result = imap_append($mbox, $user->mailbox_imap_connector_url . $folder, $msg);
    $check = imap_check($mbox);
    $after = $check->Nmsgs;
    if ($result == FALSE) {
        if (imap_createmailbox($mbox, imap_utf7_encode($user->mailbox_imap_ref . $folder))) {
            $mbox = imap_open($user->mailbox_imap_connector_url . $folder, $user->mailbox_imap_login, $user->mailbox_imap_password);
            $check = imap_check($mbox);
            $before = $check->Nmsgs;
            $result = imap_append($mbox, $user->mailbox_imap_connector_url . $folder, $msg);
            $check = imap_check($mbox);
            $after = $check->Nmsgs;
        }
    }
    imap_close($mbox);
}
    if ($res < 0) {
        $mesg = '<div class="error">' . $adh->error . '</div>';
        $db->rollback();
    } else {
        $db->commit();
    }
}
$fuser->mailbox_id = $mailboxconfig->id;
$fuser->mailbox_imap_login = $mailboxconfig->mailbox_imap_login;
$fuser->mailbox_imap_password = $mailboxconfig->mailbox_imap_password;
$fuser->mailbox_imap_host = $mailboxconfig->mailbox_imap_host;
$fuser->mailbox_imap_port = $mailboxconfig->mailbox_imap_port;
$fuser->mailbox_imap_ssl = $mailboxconfig->mailbox_imap_ssl;
$fuser->mailbox_imap_ssl_novalidate_cert = $mailboxconfig->mailbox_imap_ssl_novalidate_cert;
$fuser->mailbox_imap_ref = $mailboxconfig->get_ref();
$fuser->mailbox_imap_connector_url = $mailboxconfig->get_connector_url();
/* * *************************************************************************** */
/* Affichage fiche                                                            */
/* * *************************************************************************** */
llxHeader();
$form = new Form($db);
if ($id) {
    $head = user_prepare_head($fuser);
    $title = $langs->trans("User");
    dol_fiche_head($head, 'mailboxconfig', $title, 0, 'user');
    if ($msg) {
        print '<div class="error">' . $msg . '</div>';
    }
    print "<form method=\"post\" action=\"usertab_mailboxconfig.php\">";
    print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
    print '<input type="hidden" name="id" value="' . $id . '">';