struct mx_ops mx_imap_ops = {
.open = imap_open_mailbox,
.close = imap_close_mailbox,
+ .open_msg = imap_fetch_message,
.open_new_msg = imap_open_new_message,
.check = imap_check_mailbox_reopen,
};
/* message.c */
int imap_append_message (CONTEXT* ctx, MESSAGE* msg);
int imap_copy_messages (CONTEXT* ctx, HEADER* h, char* dest, int delete);
-int imap_fetch_message (MESSAGE* msg, CONTEXT* ctx, int msgno);
/* socket.c */
void imap_logout_all (void);
int imap_cache_del (IMAP_DATA* idata, HEADER* h);
int imap_cache_clean (IMAP_DATA* idata);
+int imap_fetch_message (CONTEXT *ctx, MESSAGE *msg, int msgno);
+
/* util.c */
#ifdef USE_HCACHE
header_cache_t* imap_hcache_open (IMAP_DATA* idata, const char* path);
return retval;
}
-int imap_fetch_message (MESSAGE *msg, CONTEXT *ctx, int msgno)
+int imap_fetch_message (CONTEXT *ctx, MESSAGE *msg, int msgno)
{
IMAP_DATA* idata;
HEADER* h;
return 0;
}
+static int mbox_open_message (CONTEXT *ctx, MESSAGE *msg, int msgno)
+{
+ msg->fp = ctx->fp;
+
+ return 0;
+}
+
static int mbox_open_new_message (MESSAGE *msg, CONTEXT *dest, HEADER *hdr)
{
msg->fp = dest->fp;
struct mx_ops mx_mbox_ops = {
.open = mbox_open_mailbox,
.close = mbox_close_mailbox,
+ .open_msg = mbox_open_message,
.open_new_msg = mbox_open_new_message,
.check = mbox_check_mailbox,
};
struct mx_ops mx_mmdf_ops = {
.open = mbox_open_mailbox,
.close = mbox_close_mailbox,
+ .open_msg = mbox_open_message,
.open_new_msg = mbox_open_new_message,
.check = mbox_check_mailbox,
};
}
}
+static int maildir_mh_open_message (CONTEXT *ctx, MESSAGE *msg, int msgno,
+ int is_maildir)
+{
+ HEADER *cur = ctx->hdrs[msgno];
+ char path[_POSIX_PATH_MAX];
+
+ snprintf (path, sizeof (path), "%s/%s", ctx->path, cur->path);
+
+ msg->fp = fopen (path, "r");
+ if (msg->fp == NULL && errno == ENOENT && is_maildir)
+ msg->fp = maildir_open_find_message (ctx->path, cur->path);
+
+ if (!msg->fp)
+ {
+ mutt_perror (path);
+ dprint (1, (debugfile, "maildir_mh_open_message: fopen: %s: %s (errno %d).\n",
+ path, strerror (errno), errno));
+ return -1;
+ }
+
+ return 0;
+}
+
+static int maildir_open_message (CONTEXT *ctx, MESSAGE *msg, int msgno)
+{
+ return maildir_mh_open_message (ctx, msg, msgno, 1);
+}
+
+static int mh_open_message (CONTEXT *ctx, MESSAGE *msg, int msgno)
+{
+ return maildir_mh_open_message (ctx, msg, msgno, 0);
+}
/*
* Open a new (temporary) message in a maildir folder.
struct mx_ops mx_maildir_ops = {
.open = maildir_open_mailbox,
.close = mh_close_mailbox,
+ .open_msg = maildir_open_message,
.open_new_msg = maildir_open_new_message,
.check = maildir_check_mailbox,
};
struct mx_ops mx_mh_ops = {
.open = mh_open_mailbox,
.close = mh_close_mailbox,
+ .open_msg = mh_open_message,
.open_new_msg = mh_open_new_message,
.check = mh_check_mailbox,
};
int (*open)(struct _context *);
int (*close)(struct _context *);
int (*check) (struct _context *ctx, int *index_hint);
+ int (*open_msg) (struct _context *, struct _message *, int msgno);
int (*open_new_msg) (struct _message *, struct _context *, HEADER *);
};
/* return a stream pointer for a message */
MESSAGE *mx_open_message (CONTEXT *ctx, int msgno)
{
+ struct mx_ops *ops = mx_get_ops (ctx->magic);
MESSAGE *msg;
-
- msg = safe_calloc (1, sizeof (MESSAGE));
- switch (msg->magic = ctx->magic)
- {
- case MUTT_MBOX:
- case MUTT_MMDF:
- msg->fp = ctx->fp;
- break;
+ int ret;
- case MUTT_MH:
- case MUTT_MAILDIR:
- {
- HEADER *cur = ctx->hdrs[msgno];
- char path[_POSIX_PATH_MAX];
-
- snprintf (path, sizeof (path), "%s/%s", ctx->path, cur->path);
-
- if ((msg->fp = fopen (path, "r")) == NULL && errno == ENOENT &&
- ctx->magic == MUTT_MAILDIR)
- msg->fp = maildir_open_find_message (ctx->path, cur->path);
-
- if (msg->fp == NULL)
- {
- mutt_perror (path);
- dprint (1, (debugfile, "mx_open_message: fopen: %s: %s (errno %d).\n",
- path, strerror (errno), errno));
- FREE (&msg);
- }
- }
- break;
-
-#ifdef USE_IMAP
- case MUTT_IMAP:
- {
- if (imap_fetch_message (msg, ctx, msgno) != 0)
- FREE (&msg);
- break;
- }
-#endif /* USE_IMAP */
+ if (!ops || !ops->open_msg)
+ {
+ dprint (1, (debugfile, "mx_open_message(): function not implemented for mailbox type %d.\n", ctx->magic));
+ return NULL;
+ }
-#ifdef USE_POP
- case MUTT_POP:
- {
- if (pop_fetch_message (msg, ctx, msgno) != 0)
- FREE (&msg);
- break;
- }
-#endif /* USE_POP */
+ msg = safe_calloc (1, sizeof (MESSAGE));
+ msg->magic = ctx->magic;
+ ret = ops->open_msg (ctx, msg, msgno);
+ if (ret)
+ FREE (&msg);
- default:
- dprint (1, (debugfile, "mx_open_message(): function not implemented for mailbox type %d.\n", ctx->magic));
- FREE (&msg);
- break;
- }
- return (msg);
+ return msg;
}
/* commit a message to a folder */
}
/* fetch message from POP server */
-int pop_fetch_message (MESSAGE* msg, CONTEXT* ctx, int msgno)
+static int pop_fetch_message (CONTEXT* ctx, MESSAGE* msg, int msgno)
{
int ret;
void *uidl;
struct mx_ops mx_pop_ops = {
.open = pop_open_mailbox,
.close = pop_close_mailbox,
+ .open_msg = pop_fetch_message,
.check = pop_check_mailbox,
};
/* pop.c */
int pop_sync_mailbox (CONTEXT *, int *);
-int pop_fetch_message (MESSAGE *, CONTEXT *, int);
int pop_close_mailbox (CONTEXT *);
void pop_fetch_mail (void);