Set the flag MUTT_NEWFOLDER to signal Maildir and MH to create the directory structure.
Distribute the "open append" code to mbox, mh, and imap/imap.c.
Set pop's mx_ops handler to NULL to signal it is not supported.
return -1;
}
-int imap_open_mailbox_append (CONTEXT *ctx)
+static int imap_open_mailbox_append (CONTEXT *ctx, int flags)
{
IMAP_DATA *idata;
char buf[LONG_STRING];
return -1;
}
- ctx->magic = MUTT_IMAP;
ctx->data = idata;
imap_fix_path (idata, mx.mbox, mailbox, sizeof (mailbox));
struct mx_ops mx_imap_ops = {
.open = imap_open_mailbox,
+ .open_append = imap_open_mailbox_append,
.close = imap_close_mailbox,
.open_msg = imap_fetch_message,
.close_msg = imap_close_message,
int imap_access (const char*, int);
int imap_check_mailbox (CONTEXT *ctx, int *index_hint, int force);
int imap_delete_mailbox (CONTEXT* idata, IMAP_MBOX mx);
-int imap_open_mailbox_append (CONTEXT *ctx);
int imap_sync_mailbox (CONTEXT *ctx, int expunge, int *index_hint);
int imap_close_mailbox (CONTEXT *ctx);
int imap_buffy_check (int force, int check_stats);
return (rc);
}
+static int mbox_open_mailbox_append (CONTEXT *ctx, int flags)
+{
+ ctx->fp = safe_fopen (ctx->path, flags & MUTT_NEWFOLDER ? "w" : "a");
+ if (!ctx->fp)
+ {
+ mutt_perror (ctx->path);
+ return -1;
+ }
+
+ if (mbox_lock_mailbox (ctx, 1, 1) != 0)
+ {
+ mutt_error (_("Couldn't lock %s\n"), ctx->path);
+ safe_fclose (&ctx->fp);
+ return -1;
+ }
+
+ fseek (ctx->fp, 0, 2);
+
+ return 0;
+}
+
static int mbox_close_mailbox (CONTEXT *ctx)
{
return 0;
struct mx_ops mx_mbox_ops = {
.open = mbox_open_mailbox,
+ .open_append = mbox_open_mailbox_append,
.close = mbox_close_mailbox,
.open_msg = mbox_open_message,
.close_msg = mbox_close_message,
struct mx_ops mx_mmdf_ops = {
.open = mbox_open_mailbox,
+ .open_append = mbox_open_mailbox_append,
.close = mbox_close_mailbox,
.open_msg = mbox_open_message,
.close_msg = mbox_close_message,
return maildir_read_dir (ctx);
}
+static int maildir_open_mailbox_append (CONTEXT *ctx, int flags)
+{
+ char tmp[_POSIX_PATH_MAX];
+
+ if (flags & MUTT_NEWFOLDER)
+ {
+ if (mkdir (ctx->path, S_IRWXU))
+ {
+ mutt_perror (ctx->path);
+ return (-1);
+ }
+
+ snprintf (tmp, sizeof (tmp), "%s/cur", ctx->path);
+ if (mkdir (tmp, S_IRWXU))
+ {
+ mutt_perror (tmp);
+ rmdir (ctx->path);
+ return (-1);
+ }
+
+ snprintf (tmp, sizeof (tmp), "%s/new", ctx->path);
+ if (mkdir (tmp, S_IRWXU))
+ {
+ mutt_perror (tmp);
+ snprintf (tmp, sizeof (tmp), "%s/cur", ctx->path);
+ rmdir (tmp);
+ rmdir (ctx->path);
+ return (-1);
+ }
+
+ snprintf (tmp, sizeof (tmp), "%s/tmp", ctx->path);
+ if (mkdir (tmp, S_IRWXU))
+ {
+ mutt_perror (tmp);
+ snprintf (tmp, sizeof (tmp), "%s/cur", ctx->path);
+ rmdir (tmp);
+ snprintf (tmp, sizeof (tmp), "%s/new", ctx->path);
+ rmdir (tmp);
+ rmdir (ctx->path);
+ return (-1);
+ }
+ }
+
+ return 0;
+}
+
static int mh_open_mailbox (CONTEXT *ctx)
{
return mh_read_dir (ctx, NULL);
}
+static int mh_open_mailbox_append (CONTEXT *ctx, int flags)
+{
+ char tmp[_POSIX_PATH_MAX];
+ int i;
+
+ if (flags & MUTT_NEWFOLDER)
+ {
+ if (mkdir (ctx->path, S_IRWXU))
+ {
+ mutt_perror (ctx->path);
+ return (-1);
+ }
+
+ snprintf (tmp, sizeof (tmp), "%s/.mh_sequences", ctx->path);
+ if ((i = creat (tmp, S_IRWXU)) == -1)
+ {
+ mutt_perror (tmp);
+ rmdir (ctx->path);
+ return (-1);
+ }
+ close (i);
+ }
+
+ return 0;
+}
+
+
/*
* Open a new (temporary) message in an MH folder.
*/
struct mx_ops mx_maildir_ops = {
.open = maildir_open_mailbox,
+ .open_append = maildir_open_mailbox_append,
.close = mh_close_mailbox,
.open_msg = maildir_open_message,
.close_msg = mh_close_message,
struct mx_ops mx_mh_ops = {
.open = mh_open_mailbox,
+ .open_append = mh_open_mailbox_append,
.close = mh_close_mailbox,
.open_msg = mh_open_message,
.close_msg = mh_close_message,
*/
struct mx_ops
{
- int (*open)(struct _context *);
- int (*close)(struct _context *);
+ int (*open) (struct _context *);
+ int (*open_append) (struct _context *, int flags);
+ int (*close) (struct _context *);
int (*check) (struct _context *ctx, int *index_hint);
int (*open_msg) (struct _context *, struct _message *, int msgno);
int (*close_msg) (struct _context *, struct _message *);
struct stat sb;
ctx->append = 1;
-
-#ifdef USE_IMAP
-
- if(mx_is_imap(ctx->path))
- return imap_open_mailbox_append (ctx);
-
-#endif
-
- if(stat(ctx->path, &sb) == 0)
+ ctx->magic = mx_get_magic (ctx->path);
+ if (ctx->magic == 0)
{
- ctx->magic = mx_get_magic (ctx->path);
-
- switch (ctx->magic)
- {
- case 0:
- mutt_error (_("%s is not a mailbox."), ctx->path);
- /* fall through */
- case -1:
- return (-1);
- }
+ mutt_error (_("%s is not a mailbox."), ctx->path);
+ return -1;
}
- else if (errno == ENOENT)
- {
- ctx->magic = DefaultMagic;
- if (ctx->magic == MUTT_MH || ctx->magic == MUTT_MAILDIR)
+ if (ctx->magic < 0)
+ {
+ if (stat (ctx->path, &sb) == -1)
{
- char tmp[_POSIX_PATH_MAX];
-
- if (mkdir (ctx->path, S_IRWXU))
- {
- mutt_perror (ctx->path);
- return (-1);
- }
-
- if (ctx->magic == MUTT_MAILDIR)
+ if (errno == ENOENT)
{
- snprintf (tmp, sizeof (tmp), "%s/cur", ctx->path);
- if (mkdir (tmp, S_IRWXU))
- {
- mutt_perror (tmp);
- rmdir (ctx->path);
- return (-1);
- }
-
- snprintf (tmp, sizeof (tmp), "%s/new", ctx->path);
- if (mkdir (tmp, S_IRWXU))
- {
- mutt_perror (tmp);
- snprintf (tmp, sizeof (tmp), "%s/cur", ctx->path);
- rmdir (tmp);
- rmdir (ctx->path);
- return (-1);
- }
- snprintf (tmp, sizeof (tmp), "%s/tmp", ctx->path);
- if (mkdir (tmp, S_IRWXU))
- {
- mutt_perror (tmp);
- snprintf (tmp, sizeof (tmp), "%s/cur", ctx->path);
- rmdir (tmp);
- snprintf (tmp, sizeof (tmp), "%s/new", ctx->path);
- rmdir (tmp);
- rmdir (ctx->path);
- return (-1);
- }
+ ctx->magic = DefaultMagic;
+ flags |= MUTT_NEWFOLDER;
}
else
{
- int i;
-
- snprintf (tmp, sizeof (tmp), "%s/.mh_sequences", ctx->path);
- if ((i = creat (tmp, S_IRWXU)) == -1)
- {
- mutt_perror (tmp);
- rmdir (ctx->path);
- return (-1);
- }
- close (i);
+ mutt_perror (ctx->path);
+ return -1;
}
}
- }
- else
- {
- mutt_perror (ctx->path);
- return (-1);
+ else
+ return -1;
}
- switch (ctx->magic)
- {
- case MUTT_MBOX:
- case MUTT_MMDF:
- if ((ctx->fp = safe_fopen (ctx->path, flags & MUTT_NEWFOLDER ? "w" : "a")) == NULL ||
- mbox_lock_mailbox (ctx, 1, 1) != 0)
- {
- if (!ctx->fp)
- mutt_perror (ctx->path);
- else
- {
- mutt_error (_("Couldn't lock %s\n"), ctx->path);
- safe_fclose (&ctx->fp);
- }
- return (-1);
- }
- fseek (ctx->fp, 0, 2);
- break;
-
- case MUTT_MH:
- case MUTT_MAILDIR:
- /* nothing to do */
- break;
-
- default:
- return (-1);
- }
+ ctx->mx_ops = mx_get_ops (ctx->magic);
+ if (!ctx->mx_ops || !ctx->mx_ops->open_append)
+ return -1;
- return 0;
+ return ctx->mx_ops->open_append (ctx, flags);
}
/* close a mailbox opened in write-mode */
struct mx_ops mx_pop_ops = {
.open = pop_open_mailbox,
+ .open_append = NULL,
.close = pop_close_mailbox,
.open_msg = pop_fetch_message,
.close_msg = pop_close_message,