/*
* Copyright (C) 1996-2002,2010,2013 Michael R. Elkins <me@mutt.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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
/* This file contains code to parse ``mbox'' and ``mmdf'' style mailboxes */
#if HAVE_CONFIG_H
# include "config.h"
#endif
#include "mutt.h"
#include "mailbox.h"
#include "mx.h"
#include "sort.h"
#include "copy.h"
#include "mutt_curses.h"
#include <sys/stat.h>
#include <dirent.h>
#include <string.h>
#include <utime.h>
#include <sys/file.h>
#include <errno.h>
#include <unistd.h>
#include <fcntl.h>
/* struct used by mutt_sync_mailbox() to store new offsets */
struct m_update_t
{
short valid;
LOFF_T hdr;
LOFF_T body;
long lines;
LOFF_T length;
};
/* parameters:
* ctx - context to lock
* excl - exclusive lock?
* retry - should retry if unable to lock?
*/
int mbox_lock_mailbox (CONTEXT *ctx, int excl, int retry)
{
int r;
if ((r = mx_lock_file (ctx->path, fileno (ctx->fp), excl, 1, retry)) == 0)
ctx->locked = 1;
else if (retry && !excl