/*****************************************************************************

  POPular -- A POP3 server and proxy for large mail systems

  $Id: mailbox.c,v 1.1 2001/04/30 12:20:34 sqrt Exp $

  http://www.remote.org/jochen/mail/popular/

******************************************************************************

  Copyright (C) 1999-2001  Jochen Topf <jochen@remote.org>

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA

*****************************************************************************/

#if HAVE_CONFIG_H
# include <config.h>
#endif

#include "popular.h"


/*****************************************************************************

  mailbox_prepdir()
  
  Change into maildir. If it is not there, create it.

*****************************************************************************/
int
mailbox_prepdir(const char *mbdir)
{
  if (chdir(mbdir) == 0) return 1;

  if (errno != ENOENT) {
    /* XLOG-DOC:ADM:0063:no_mailbox
     * Changing into mailbox directory failed. */
    xlog_printf(xlog_adm, 0x0063, "no_mailbox mailbox='%s' errno=%d errmsg='%s'", mbdir, errno, strerror(errno));
    return 0;
  }

  if (mkdir(mbdir, MAILDIRMODE) < 0) {
    /* XLOG-DOC:ADM:0064:mkdir_failed
     * Creation of the mailbox directory failed. */
    xlog_printf(xlog_adm, 0x0064, "mkdir_failed mailbox='%s' errno=%d errmsg='%s'", mbdir, errno, strerror(errno));
    return 0;
  }

  if (chdir(mbdir) != 0) {
    /* XLOG-DOC:ADM:0065:no_mailbox
     * Changing into mailbox directory failed. */
    xlog_printf(xlog_adm, 0x0065, "no_mailbox mailbox='%s' errno=%d errmsg='%s'", mbdir, errno, strerror(errno));
    return 0;
  }

  if (mkdir("new", MAILDIRMODE) < 0) {
    /* XLOG-DOC:ADM:0066:mkdir_failed
     * Creation of the 'new' directory failed. */
    xlog_printf(xlog_adm, 0x0066, "mkdir_failed file='new' errno=%d errmsg='%s'", errno, strerror(errno));
    return 0;
  }
  if (mkdir("cur", MAILDIRMODE) < 0) {
    /* XLOG-DOC:ADM:0067:mkdir_failed
     * Creation of the 'cur' directory failed. */
    xlog_printf(xlog_adm, 0x0067, "mkdir_failed file='cur' errno=%d errmsg='%s'", errno, strerror(errno));
    return 0;
  }
  if (mkdir("tmp", MAILDIRMODE) < 0) {
    /* XLOG-DOC:ADM:0068:mkdir_failed
     * Creation of the 'tmp' directory failed. */
    xlog_printf(xlog_adm, 0x0068, "mkdir_failed file='tmp' errno=%d errmsg='%s'", errno, strerror(errno));
    return 0;
  }

  return 1;
}


/** THE END *****************************************************************/


syntax highlighted by Code2HTML, v. 0.9.1