/*
* Copyright (C) 1996-2000 Michael R. Elkins <me@cs.hmc.edu>
* Copyright (C) 1999-2000 Thomas Roessler <roessler@guug.de>
*
* 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, USA.
*/
/*
* This file contains routines specific to MH and ``maildir'' style
* mailboxes.
*/
#include "mutt.h"
#include "mailbox.h"
#include "mx.h"
#include "copy.h"
#include "buffy.h"
#include "sort.h"
#include <sys/stat.h>
#include <dirent.h>
#include <limits.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <errno.h>
#include <string.h>
struct maildir
{
HEADER *h;
char *canon_fname;
struct maildir *next;
};
static void maildir_free_entry(struct maildir **md)
{
if(!md || !*md)
return;
safe_free((void **) &(*md)->canon_fname);
if((*md)->h)
mutt_free_header(&(*md)->h);
safe_free((void **) md);
}
static void maildir_free_maildir(struct maildir **md)
{
struct maildir *p, *q;
if(!md || !*md)
return;
for(p = *md; p; p = q)
{
q = p->next;
maildir_free_entry(&p);
}
}
static void maildir_parse_flags(HEADER *h, const char *path)
{
char *p;
h->flagged = 0;
h->read = 0;
h->replied = 0;
if ((p = strrchr (path, ':')) != NULL && mutt_strncmp (p + 1, "2,", 2) == 0)
{
p += 3;
while (*p)
{
switch (*p)
{
case 'F':
h->flagged = 1;
break;
case 'S': /* seen */
h->read = 1;
break;
case 'R': /* replied */
h->replied = 1;
break;
}
p++;
}
}
}
static void maildir_update_mtime(CONTEXT *ctx)
{
char buf[_POSIX_PATH_MAX];
struct stat st;
if(ctx->magic == M_MAILDIR)
{
snprintf(buf, sizeof(buf), "%s/%s", ctx->path, "cur");
if(stat (buf, &st) == 0)
ctx->mtime_cur = st.st_mtime;
snprintf(buf, sizeof(buf), "%s/%s", ctx->path, "new");
}
else
strfcpy(buf, ctx->path, sizeof(buf));
if(stat(buf, &st) == 0)
ctx->mtime = st.st_mtime;
}
static HEADER *maildir_parse_message(int magic, const char *fname, int is_old)
{
FILE *f;
HEADER *h = NULL;
struct stat st;
if ((f = fopen (fname, "r")) != NULL)
{
h = mutt_new_header();
h->env = mutt_read_rfc822_header (f, h, 0, 0);
fstat (fileno (f), &st);
fclose (f);
if (!h->received)
h->received = h->date_sent;
if (h->content->length <= 0)
h->content->length = st.st_size - h->content->offset;
h->index = -1;
if (magic ==