{
struct stat s;
struct Buffer *md = NULL;
+ struct Buffer *mailbox = NULL;
#ifdef USE_NNTP
if (OptNews)
if (STAILQ_EMPTY(&AllMailboxes))
return -1;
+ mailbox = mutt_buffer_pool_get();
md = mutt_buffer_pool_get();
mutt_mailbox_check(Context ? Context->mailbox : NULL, 0);
np->mailbox->msg_unread = Context->mailbox->msg_unread;
}
- char buf[PATH_MAX];
- mutt_str_strfcpy(buf, mutt_b2s(np->mailbox->pathbuf), sizeof(buf));
+ mutt_buffer_strcpy(mailbox, mutt_b2s(np->mailbox->pathbuf));
if (C_BrowserAbbreviateMailboxes)
- mutt_pretty_mailbox(buf, sizeof(buf));
+ mutt_buffer_pretty_mailbox(mailbox);
switch (np->mailbox->magic)
{
case MUTT_IMAP:
case MUTT_POP:
- add_folder(menu, state, buf, np->mailbox->desc, NULL, np->mailbox, NULL);
+ add_folder(menu, state, mutt_b2s(mailbox), np->mailbox->desc, NULL,
+ np->mailbox, NULL);
continue;
case MUTT_NOTMUCH:
case MUTT_NNTP:
s.st_mtime = st2.st_mtime;
}
- add_folder(menu, state, buf, np->mailbox->desc, &s, np->mailbox, NULL);
+ add_folder(menu, state, mutt_b2s(mailbox), np->mailbox->desc, &s, np->mailbox, NULL);
}
}
browser_sort(state);
+ mutt_buffer_pool_release(&mailbox);
mutt_buffer_pool_release(&md);
return 0;
}
*/
bool mutt_mailbox_list(void)
{
- char path[PATH_MAX];
char mailboxlist[512];
size_t pos = 0;
int first = 1;
int have_unnotified = MailboxNotify;
+ struct Buffer *path = mutt_buffer_pool_get();
+
mailboxlist[0] = '\0';
pos += strlen(strncat(mailboxlist, _("New mail in "), sizeof(mailboxlist) - 1 - pos));
struct MailboxNode *np = NULL;
if (!np->mailbox->has_new || (have_unnotified && np->mailbox->notified))
continue;
- mutt_str_strfcpy(path, mutt_b2s(np->mailbox->pathbuf), sizeof(path));
- mutt_pretty_mailbox(path, sizeof(path));
+ mutt_buffer_strcpy(path, mutt_b2s(np->mailbox->pathbuf));
+ mutt_buffer_pretty_mailbox(path);
if (!first && (MuttMessageWindow->cols >= 7) &&
- (pos + strlen(path) >= (size_t) MuttMessageWindow->cols - 7))
+ ((pos + mutt_buffer_len(path)) >= ((size_t) MuttMessageWindow->cols - 7)))
{
break;
}
np->mailbox->notified = true;
MailboxNotify--;
}
- pos += strlen(strncat(mailboxlist + pos, path, sizeof(mailboxlist) - 1 - pos));
+ pos += strlen(strncat(mailboxlist + pos, mutt_b2s(path), sizeof(mailboxlist) - 1 - pos));
first = 0;
}
{
strncat(mailboxlist + pos, ", ...", sizeof(mailboxlist) - 1 - pos);
}
+
+ mutt_buffer_pool_release(&path);
+
if (!first)
{
mutt_message("%s", mailboxlist);
return true;
}
- /* there were no mailboxes needing to be notified, so clean up since
- * MailboxNotify has somehow gotten out of sync */
- MailboxNotify = 0;
- return false;
+ else
+ {
+ /* there were no mailboxes needing to be notified, so clean up since
+ * MailboxNotify has somehow gotten out of sync */
+ MailboxNotify = 0;
+ return false;
+ }
}
/**
dev_t st_dev;
ino_t st_ino;
struct Monitor *monitor;
- char path_buf[PATH_MAX]; /* access via path only (maybe not initialized) */
+ struct Buffer *path_buf; /* access via path only (maybe not initialized) */
};
/**
return monitor;
}
+/**
+ * monitor_info_init - Set up a file monitor
+ * @param info Monitor to initialise
+ */
+static void monitor_info_init(struct MonitorInfo *info)
+{
+ memset(info, 0, sizeof(*info));
+}
+
+/**
+ * monitor_info_free - Shutdown a file monitor
+ * @param info Monitor to shut down
+ */
+static void monitor_info_free(struct MonitorInfo *info)
+{
+ mutt_buffer_free(&info->path_buf);
+}
+
/**
* monitor_delete - Free a file monitor
* @param monitor Monitor to free
if (fmt)
{
- snprintf(info->path_buf, sizeof(info->path_buf), fmt, info->path);
- info->path = info->path_buf;
+ if (!info->path_buf)
+ info->path_buf = mutt_buffer_new();
+ mutt_buffer_printf(info->path_buf, fmt, info->path);
+ info->path = mutt_b2s(info->path_buf);
}
if (stat(info->path, &sb) != 0)
return RESOLVERES_FAIL_STAT;
int mutt_monitor_add(struct Mailbox *m)
{
struct MonitorInfo info;
+ monitor_info_init(&info);
+ int rc = 0;
int desc = monitor_resolve(&info, m);
if (desc != RESOLVERES_OK_NOTEXISTING)
{
if (!m && (desc == RESOLVERES_OK_EXISTING))
MonitorContextDescriptor = info.monitor->desc;
- return (desc == RESOLVERES_OK_EXISTING) ? 0 : -1;
+ rc = (desc == RESOLVERES_OK_EXISTING) ? 0 : -1;
+ goto cleanup;
}
uint32_t mask = info.isdir ? INOTIFY_MASK_DIR : INOTIFY_MASK_FILE;
{
mutt_debug(LL_DEBUG2, "inotify_add_watch failed for '%s', errno=%d %s\n",
info.path, errno, strerror(errno));
- return -1;
+ rc = -1;
+ goto cleanup;
}
mutt_debug(LL_DEBUG3, "inotify_add_watch descriptor=%d for '%s'\n", desc, info.path);
MonitorContextDescriptor = desc;
monitor_new(&info, desc);
- return 0;
+
+cleanup:
+ monitor_info_free(&info);
+ return rc;
}
/**
int mutt_monitor_remove(struct Mailbox *m)
{
struct MonitorInfo info, info2;
+ int rc = 0;
+
+ monitor_info_init(&info);
+ monitor_info_init(&info2);
if (!m)
{
}
if (monitor_resolve(&info, m) != RESOLVERES_OK_EXISTING)
- return 2;
+ {
+ rc = 2;
+ goto cleanup;
+ }
if (Context)
{
if ((monitor_resolve(&info2, NULL) == RESOLVERES_OK_EXISTING) &&
(info.st_ino == info2.st_ino) && (info.st_dev == info2.st_dev))
{
- return 1;
+ rc = 1;
+ goto cleanup;
}
}
else
{
if (mutt_find_mailbox(Context->mailbox->realpath))
- return 1;
+ {
+ rc = 1;
+ goto cleanup;
+ }
}
}
monitor_delete(info.monitor);
monitor_check_free();
- return 0;
+
+cleanup:
+ monitor_info_free(&info);
+ monitor_info_free(&info2);
+ return rc;
}