summaryrefslogtreecommitdiffstats
path: root/mx.c
diff options
context:
space:
mode:
authorThomas Roessler <roessler@does-not-exist.org>1999-07-01 09:45:12 +0000
committerThomas Roessler <roessler@does-not-exist.org>1999-07-01 09:45:12 +0000
commit32016c8f74f4914c71e2c006c82ab7a6c7ddebd6 (patch)
tree3bc556f813a6d8377bddefaf21c36621d56928a0 /mx.c
parentedfda8e884b92c31e0fe1c9a27cc32077862059f (diff)
Various patches from last week, including:
- new mh/maildir access code. - subscribe/unsubscribe - various fixes.
Diffstat (limited to 'mx.c')
-rw-r--r--mx.c187
1 files changed, 84 insertions, 103 deletions
diff --git a/mx.c b/mx.c
index 12d696e5..ae0bfd57 100644
--- a/mx.c
+++ b/mx.c
@@ -706,7 +706,7 @@ static int sync_mailbox (CONTEXT *ctx)
}
#if 0
- if (!ctx->quiet && rc == -1)
+ if (!ctx->quiet && !ctx->shutup && rc == -1)
mutt_error ( _("Could not synchronize mailbox %s!"), ctx->path);
#endif
@@ -1015,70 +1015,8 @@ int mx_sync_mailbox (CONTEXT *ctx)
return (rc);
}
-int mh_open_new_message (MESSAGE *msg, CONTEXT *dest, HEADER *hdr)
-{
- int hi = 0;
- int fd, n;
- char *cp;
- char path[_POSIX_PATH_MAX];
- DIR *dirp;
- struct dirent *de;
-
- do
- {
- if ((dirp = opendir (dest->path)) == NULL)
- {
- mutt_perror (dest->path);
- return (-1);
- }
- /* figure out what the next message number is */
- while ((de = readdir (dirp)) != NULL)
- {
- cp = de->d_name;
- while (*cp)
- {
- if (!isdigit ((unsigned char) *cp))
- break;
- cp++;
- }
- if (!*cp)
- {
- n = atoi (de->d_name);
- if (n > hi)
- hi = n;
- }
- }
- closedir (dirp);
- hi++;
- snprintf (path, sizeof (path), "%s/%d", dest->path, hi);
- if ((fd = open (path, O_WRONLY | O_EXCL | O_CREAT, 0600)) == -1)
- {
- if (errno != EEXIST)
- {
- mutt_perror (path);
- return (-1);
- }
- }
- }
- while (fd < 0);
-
- if ((msg->fp = fdopen (fd, "w")) == NULL)
- return (-1);
-
- return 0;
-}
-
-int maildir_open_new_message (MESSAGE *msg, CONTEXT *dest, HEADER *hdr)
-{
- char tmp[_POSIX_PATH_MAX];
- char path[_POSIX_PATH_MAX];
-
- maildir_create_filename (dest->path, hdr, path, tmp);
- if ((msg->fp = safe_fopen (tmp, "w")) == NULL)
- return (-1);
- return 0;
-}
+/* {maildir,mh}_open_new_message are in mh.c. */
int mbox_open_new_message (MESSAGE *msg, CONTEXT *dest, HEADER *hdr)
{
@@ -1213,30 +1151,31 @@ MESSAGE *mx_open_message (CONTEXT *ctx, int msgno)
case M_MH:
case M_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)
{
- 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)
- {
- mutt_perror (path);
- dprint (1, (debugfile, "mx_open_message: fopen: %s: %s (errno %d).\n",
- path, strerror (errno), errno));
- FREE (&msg);
- }
+ mutt_perror (path);
+ dprint (1, (debugfile, "mx_open_message: fopen: %s: %s (errno %d).\n",
+ path, strerror (errno), errno));
+ FREE (&msg);
}
- break;
-
+ }
+ break;
+
#ifdef USE_IMAP
case M_IMAP:
+ {
if (imap_fetch_message (msg, ctx, msgno) != 0)
FREE (&msg);
break;
+ }
#endif /* USE_IMAP */
default:
-
dprint (1, (debugfile, "mx_open_message(): function not implemented for mailbox type %d.\n", ctx->magic));
FREE (&msg);
break;
@@ -1244,45 +1183,87 @@ MESSAGE *mx_open_message (CONTEXT *ctx, int msgno)
return (msg);
}
-/* close a pointer to a message */
-int mx_close_message (MESSAGE **msg)
+/* commit a message to a folder */
+
+int mx_commit_message (MESSAGE *msg, CONTEXT *ctx)
{
int r = 0;
- if ((*msg)->write)
+ if (!(msg->write && ctx->append))
+ {
+ dprint (1, (debugfile, "mx_commit_message(): msg->write = %d, ctx->append = %d\n",
+ msg->write, ctx->append));
+ return -1;
+ }
+
+ switch (msg->magic)
{
- /* add the message terminator */
- switch ((*msg)->magic)
+ case M_MMDF:
{
- case M_MMDF:
- fputs (MMDF_SEP, (*msg)->fp);
- break;
+ fputs (MMDF_SEP, msg->fp);
+ break;
+ }
+
+ case M_MBOX:
+ {
+ fputc ('\n', msg->fp);
+ break;
+ }
- case M_MBOX:
- fputc ('\n', (*msg)->fp);
- break;
+ case M_KENDRA:
+ {
+ fputs (KENDRA_SEP, msg->fp);
+ break;
}
- }
- switch ((*msg)->magic)
- {
- case M_MH:
+#ifdef USE_IMAP
+ case M_IMAP:
+ {
+ if ((r = safe_fclose (&msg->fp)) == 0)
+ r = imap_append_message (ctx, msg);
+ break;
+ }
+#endif
+
case M_MAILDIR:
- r = fclose ((*msg)->fp);
+ {
+ if ((r = safe_fclose (&msg->fp)) == 0)
+ r = maildir_commit_message (ctx, msg, NULL);
+ break;
+ }
+
+ case M_MH:
+ {
+ if ((r = safe_fclose (&msg->fp)) == 0)
+ r = mh_commit_message (ctx, msg, NULL);
break;
+ }
+ }
+ return r;
+}
+
+/* close a pointer to a message */
+int mx_close_message (MESSAGE **msg)
+{
+ int r = 0;
+ if ((*msg)->magic == M_MH || (*msg)->magic == M_MAILDIR
#ifdef USE_IMAP
- case M_IMAP:
- r = fclose ((*msg)->fp);
- if ((*msg)->write && (*msg)->ctx->append)
- {
- r = imap_append_message ((*msg)->ctx, *msg);
- unlink ((*msg)->path);
- }
+ || (*msg)->magic == M_IMAP
#endif
+ )
+ {
+ r = safe_fclose (&(*msg)->fp);
+ }
+ else
+ (*msg)->fp = NULL;
- default:
- break;
+ if ((*msg)->path)
+ {
+ dprint (1, (debugfile, "mx_close_message (): unlinking %s\n",
+ (*msg)->path));
+ unlink ((*msg)->path);
+ FREE (&(*msg)->path);
}
FREE (msg);