static int examine_mailboxes (MUTTMENU *menu, struct browser_state *state)
{
struct stat s;
- char buffer[LONG_STRING];
BUFFY *tmp = Incoming;
+ BUFFER *mailbox = NULL;
BUFFER *md = NULL;
if (!Incoming)
return (-1);
mutt_buffy_check (0);
+ mailbox = mutt_buffer_pool_get ();
md = mutt_buffer_pool_get ();
init_state (state, menu);
tmp->msg_unread = Context->unread;
}
- strfcpy (buffer, mutt_b2s (tmp->pathbuf), sizeof (buffer));
+ mutt_buffer_strcpy (mailbox, mutt_b2s (tmp->pathbuf));
if (option (OPTBROWSERABBRMAILBOXES))
- mutt_pretty_mailbox (buffer, sizeof (buffer));
+ mutt_buffer_pretty_mailbox (mailbox);
#ifdef USE_IMAP
if (mx_is_imap (mutt_b2s (tmp->pathbuf)))
{
- add_folder (menu, state, buffer, NULL, tmp);
+ add_folder (menu, state, mutt_b2s (mailbox), NULL, tmp);
continue;
}
#endif
#ifdef USE_POP
if (mx_is_pop (mutt_b2s (tmp->pathbuf)))
{
- add_folder (menu, state, buffer, NULL, tmp);
+ add_folder (menu, state, mutt_b2s (mailbox), NULL, tmp);
continue;
}
#endif
s.st_mtime = st2.st_mtime;
}
- add_folder (menu, state, buffer, &s, tmp);
+ add_folder (menu, state, mutt_b2s (mailbox), &s, tmp);
}
while ((tmp = tmp->next));
browser_sort (state);
+ mutt_buffer_pool_release (&mailbox);
mutt_buffer_pool_release (&md);
return 0;
}
int mutt_buffy_list (void)
{
BUFFY *tmp;
- char path[_POSIX_PATH_MAX];
+ BUFFER *path = NULL;
char buffylist[2*STRING];
size_t pos = 0;
int first = 1;
int have_unnotified = BuffyNotify;
+ path = mutt_buffer_pool_get ();
+
buffylist[0] = 0;
pos += strlen (strncat (buffylist, _("New mail in "), sizeof (buffylist) - 1 - pos)); /* __STRNCAT_CHECKED__ */
for (tmp = Incoming; tmp; tmp = tmp->next)
if (!tmp->new || (have_unnotified && tmp->notified))
continue;
- strfcpy (path, mutt_b2s (tmp->pathbuf), sizeof (path));
- mutt_pretty_mailbox (path, sizeof (path));
+ mutt_buffer_strcpy (path, mutt_b2s (tmp->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;
if (!first)
tmp->notified = 1;
BuffyNotify--;
}
- pos += strlen (strncat(buffylist + pos, path, sizeof(buffylist)-1-pos)); /* __STRNCAT_CHECKED__ */
+ pos += strlen (strncat(buffylist + pos, mutt_b2s (path), sizeof(buffylist)-1-pos)); /* __STRNCAT_CHECKED__ */
first = 0;
}
if (!first && tmp)
{
strncat (buffylist + pos, ", ...", sizeof (buffylist) - 1 - pos); /* __STRNCAT_CHECKED__ */
}
+
+ mutt_buffer_pool_release (&path);
+
if (!first)
{
mutt_message ("%s", buffylist);
return (1);
}
- /* there were no mailboxes needing to be notified, so clean up since
- * BuffyNotify has somehow gotten out of sync
- */
- BuffyNotify = 0;
- return (0);
+ else
+ {
+ /* there were no mailboxes needing to be notified, so clean up since
+ * BuffyNotify has somehow gotten out of sync
+ */
+ BuffyNotify = 0;
+ return (0);
+ }
}
void mutt_buffy_setnotified (const char *path)
static BUFFY* buffy_get (const char *path)
{
BUFFY *cur;
- char *epath;
+ BUFFER *epath;
if (!path)
return NULL;
- epath = safe_strdup(path);
- mutt_expand_path(epath, mutt_strlen(epath));
+ epath = mutt_buffer_pool_get ();
+ mutt_buffer_strcpy (epath, NONULL (path));
+ mutt_buffer_expand_path (epath);
for (cur = Incoming; cur; cur = cur->next)
{
/* must be done late because e.g. IMAP delimiter may change */
mutt_buffer_expand_path (cur->pathbuf);
- if (!mutt_strcmp (mutt_b2s (cur->pathbuf), path))
+ if (!mutt_strcmp (mutt_b2s (cur->pathbuf), mutt_b2s (epath)))
{
- FREE (&epath);
+ mutt_buffer_pool_release (&epath);
return cur;
}
}
- FREE (&epath);
+ mutt_buffer_pool_release (&epath);
return NULL;
}
dev_t st_dev;
ino_t st_ino;
MONITOR *monitor;
- char _pathbuf[_POSIX_PATH_MAX]; /* access via path only (maybe not initialized) */
+ BUFFER *_pathbuf; /* access via path only (maybe not initialized) */
}
MONITORINFO;
return monitor;
}
+static void monitor_info_init (MONITORINFO *info)
+{
+ memset (info, 0, sizeof (MONITORINFO));
+}
+
+static void monitor_info_free (MONITORINFO *info)
+{
+ mutt_buffer_free (&info->_pathbuf);
+}
+
static void monitor_delete (MONITOR *monitor)
{
MONITOR **ptr = &Monitor;
if (fmt)
{
- snprintf (info->_pathbuf, sizeof(info->_pathbuf), fmt, info->path);
- info->path = info->_pathbuf;
+ if (!info->_pathbuf)
+ info->_pathbuf = mutt_buffer_new ();
+ mutt_buffer_printf (info->_pathbuf, fmt, info->path);
+ info->path = mutt_b2s (info->_pathbuf);
}
if (stat (info->path, &sb) != 0)
return RESOLVERES_FAIL_STAT;
{
MONITORINFO info;
uint32_t mask;
- int descr;
+ int descr, rc = 0;
+
+ monitor_info_init (&info);
descr = monitor_resolve (&info, buffy);
if (descr != RESOLVERES_OK_NOTEXISTING)
{
if (!buffy && (descr == RESOLVERES_OK_EXISTING))
MonitorContextDescriptor = info.monitor->descr;
- return descr == RESOLVERES_OK_EXISTING ? 0 : -1;
+ rc = descr == RESOLVERES_OK_EXISTING ? 0 : -1;
+ goto cleanup;
}
mask = info.isdir ? INOTIFY_MASK_DIR : INOTIFY_MASK_FILE;
|| (descr = inotify_add_watch (INotifyFd, info.path, mask)) == -1)
{
dprint (2, (debugfile, "monitor: inotify_add_watch failed for '%s', errno=%d %s\n", info.path, errno, strerror(errno)));
- return -1;
+ rc = -1;
+ goto cleanup;
}
dprint (3, (debugfile, "monitor: inotify_add_watch descriptor=%d for '%s'\n", descr, info.path));
MonitorContextDescriptor = descr;
monitor_create (&info, descr);
- return 0;
+
+cleanup:
+ monitor_info_free (&info);
+ return rc;
}
/* mutt_monitor_remove: remove file monitor from BUFFY, or - if NULL - from Context.
int mutt_monitor_remove (BUFFY *buffy)
{
MONITORINFO info, info2;
+ int rc = 0;
+
+ monitor_info_init (&info);
+ monitor_info_init (&info2);
if (!buffy)
{
}
if (monitor_resolve (&info, buffy) != 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->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;
}