struct MailboxList AllMailboxes = STAILQ_HEAD_INITIALIZER(AllMailboxes);
-/**
- * get_mailbox_description - Find a mailbox's description given a path.
- * @param path Path to the mailbox
- * @retval ptr Description
- * @retval NULL No mailbox matching path
- */
-static char *get_mailbox_description(const char *path)
-{
- struct MailboxNode *np = NULL;
- STAILQ_FOREACH(np, &AllMailboxes, entries)
- {
- if (np->m->desc && (strcmp(np->m->path, path) == 0))
- return np->m->desc;
- }
- return NULL;
-}
-
/**
* mailbox_new - Create a new Mailbox
* @param path Path to the mailbox
*/
struct Mailbox *mailbox_new(const char *path)
{
- char rp[PATH_MAX] = "";
+ // char rp[PATH_MAX] = "";
- struct Mailbox *mailbox = mutt_mem_calloc(1, sizeof(struct Mailbox));
- mutt_str_strfcpy(mailbox->path, path, sizeof(mailbox->path));
- char *r = realpath(path, rp);
- mutt_str_strfcpy(mailbox->realpath, r ? rp : path, sizeof(mailbox->realpath));
- mailbox->magic = MUTT_UNKNOWN;
- mailbox->desc = get_mailbox_description(mailbox->path);
+ struct Mailbox *m = mutt_mem_calloc(1, sizeof(struct Mailbox));
+ // mutt_str_strfcpy(m->path, path, sizeof(m->path));
+ // char *r = realpath(path, rp);
+ // mutt_str_strfcpy(m->realpath, r ? rp : path, sizeof(m->realpath));
+ // m->magic = MUTT_UNKNOWN;
+ // m->desc = get_mailbox_description(m->path);
- return mailbox;
+ return m;
}
/**
* mailbox_free - Free a Mailbox
- * @param mailbox Mailbox to free
+ * @param m Mailbox to free
*/
-void mailbox_free(struct Mailbox **mailbox)
+void mailbox_free(struct Mailbox **m)
{
- if (!mailbox || !*mailbox)
+ if (!m || !*m)
return;
- FREE(&(*mailbox)->desc);
- if ((*mailbox)->mdata && (*mailbox)->free_mdata)
- (*mailbox)->free_mdata(&(*mailbox)->mdata);
- FREE(mailbox);
+ FREE(&(*m)->desc);
+ if ((*m)->mdata && (*m)->free_mdata)
+ (*m)->free_mdata(&(*m)->mdata);
+ FREE(m);
}
/**
* mailbox_maildir_check_dir - Check for new mail / mail counts
- * @param mailbox Mailbox to check
- * @param dir_name Path to mailbox
+ * @param m Mailbox to check
+ * @param dir_name Path to Mailbox
* @param check_new if true, check for new mail
* @param check_stats if true, count total, new, and flagged messages
* @retval 1 if the dir has new mail
*
* Checks the specified maildir subdir (cur or new) for new mail or mail counts.
*/
-static int mailbox_maildir_check_dir(struct Mailbox *mailbox, const char *dir_name,
+static int mailbox_maildir_check_dir(struct Mailbox *m, const char *dir_name,
bool check_new, bool check_stats)
{
DIR *dirp = NULL;
struct Buffer *path = mutt_buffer_pool_get();
struct Buffer *msgpath = mutt_buffer_pool_get();
- mutt_buffer_printf(path, "%s/%s", mailbox->path, dir_name);
+ mutt_buffer_printf(path, "%s/%s", m->path, dir_name);
/* when $mail_check_recent is set, if the new/ directory hasn't been modified since
- * the user last exited the mailbox, then we know there is no recent mail.
+ * the user last exited the m, then we know there is no recent mail.
*/
if (check_new && MailCheckRecent)
{
if (stat(mutt_b2s(path), &sb) == 0 &&
- mutt_stat_timespec_compare(&sb, MUTT_STAT_MTIME, &mailbox->last_visited) < 0)
+ mutt_stat_timespec_compare(&sb, MUTT_STAT_MTIME, &m->last_visited) < 0)
{
rc = 0;
check_new = false;
dirp = opendir(mutt_b2s(path));
if (!dirp)
{
- mailbox->magic = MUTT_UNKNOWN;
+ m->magic = MUTT_UNKNOWN;
rc = 0;
goto cleanup;
}
if (check_stats)
{
- mailbox->msg_count++;
+ m->msg_count++;
if (p && strchr(p + 3, 'F'))
- mailbox->msg_flagged++;
+ m->msg_flagged++;
}
if (!p || !strchr(p + 3, 'S'))
{
if (check_stats)
- mailbox->msg_unread++;
+ m->msg_unread++;
if (check_new)
{
if (MailCheckRecent)
{
mutt_buffer_printf(msgpath, "%s/%s", mutt_b2s(path), de->d_name);
- /* ensure this message was received since leaving this mailbox */
+ /* ensure this message was received since leaving this m */
if (stat(mutt_b2s(msgpath), &sb) == 0 &&
- (mutt_stat_timespec_compare(&sb, MUTT_STAT_CTIME, &mailbox->last_visited) <= 0))
+ (mutt_stat_timespec_compare(&sb, MUTT_STAT_CTIME, &m->last_visited) <= 0))
{
continue;
}
}
- mailbox->has_new = true;
+ m->has_new = true;
rc = 1;
check_new = false;
if (!check_stats)
/**
* mailbox_maildir_check - Check for new mail in a maildir mailbox
- * @param mailbox Mailbox to check
+ * @param m Mailbox to check
* @param check_stats if true, also count total, new, and flagged messages
* @retval 1 if the mailbox has new mail
*/
-static int mailbox_maildir_check(struct Mailbox *mailbox, bool check_stats)
+static int mailbox_maildir_check(struct Mailbox *m, bool check_stats)
{
int rc = 1;
bool check_new = true;
if (check_stats)
{
- mailbox->msg_count = 0;
- mailbox->msg_unread = 0;
- mailbox->msg_flagged = 0;
+ m->msg_count = 0;
+ m->msg_unread = 0;
+ m->msg_flagged = 0;
}
- rc = mailbox_maildir_check_dir(mailbox, "new", check_new, check_stats);
+ rc = mailbox_maildir_check_dir(m, "new", check_new, check_stats);
check_new = !rc && MaildirCheckCur;
if (check_new || check_stats)
- if (mailbox_maildir_check_dir(mailbox, "cur", check_new, check_stats))
+ if (mailbox_maildir_check_dir(m, "cur", check_new, check_stats))
rc = 1;
return rc;
/**
* mailbox_mbox_check - Check for new mail for an mbox mailbox
- * @param mailbox Mailbox to check
+ * @param m Mailbox to check
* @param sb stat(2) information about the mailbox
* @param check_stats if true, also count total, new, and flagged messages
* @retval 1 if the mailbox has new mail
*/
-static int mailbox_mbox_check(struct Mailbox *mailbox, struct stat *sb, bool check_stats)
+static int mailbox_mbox_check(struct Mailbox *m, struct stat *sb, bool check_stats)
{
int rc = 0;
bool new_or_changed;
if (CheckMboxSize)
- new_or_changed = (sb->st_size > mailbox->size);
+ new_or_changed = (sb->st_size > m->size);
else
{
new_or_changed =
(mutt_stat_compare(sb, MUTT_STAT_MTIME, sb, MUTT_STAT_ATIME) > 0) ||
- (mailbox->newly_created &&
+ (m->newly_created &&
(mutt_stat_compare(sb, MUTT_STAT_CTIME, sb, MUTT_STAT_MTIME) == 0) &&
(mutt_stat_compare(sb, MUTT_STAT_CTIME, sb, MUTT_STAT_ATIME) == 0));
}
if (new_or_changed)
{
if (!MailCheckRecent ||
- (mutt_stat_timespec_compare(sb, MUTT_STAT_MTIME, &mailbox->last_visited) > 0))
+ (mutt_stat_timespec_compare(sb, MUTT_STAT_MTIME, &m->last_visited) > 0))
{
rc = 1;
- mailbox->has_new = true;
+ m->has_new = true;
}
}
else if (CheckMboxSize)
{
/* some other program has deleted mail from the folder */
- mailbox->size = (off_t) sb->st_size;
+ m->size = (off_t) sb->st_size;
}
- if (mailbox->newly_created && (sb->st_ctime != sb->st_mtime || sb->st_ctime != sb->st_atime))
- mailbox->newly_created = false;
+ if (m->newly_created && (sb->st_ctime != sb->st_mtime || sb->st_ctime != sb->st_atime))
+ m->newly_created = false;
if (check_stats &&
- (mutt_stat_timespec_compare(sb, MUTT_STAT_MTIME, &mailbox->stats_last_checked) > 0))
+ (mutt_stat_timespec_compare(sb, MUTT_STAT_MTIME, &m->stats_last_checked) > 0))
{
struct Context *ctx =
- mx_mbox_open(mailbox->path, MUTT_READONLY | MUTT_QUIET | MUTT_NOSORT | MUTT_PEEK);
+ mx_mbox_open(m->path, MUTT_READONLY | MUTT_QUIET | MUTT_NOSORT | MUTT_PEEK);
if (ctx)
{
- mailbox->msg_count = ctx->mailbox->msg_count;
- mailbox->msg_unread = ctx->mailbox->msg_unread;
- mailbox->msg_flagged = ctx->mailbox->msg_flagged;
- mailbox->stats_last_checked = ctx->mailbox->mtime;
+ m->msg_count = ctx->mailbox->msg_count;
+ m->msg_unread = ctx->mailbox->msg_unread;
+ m->msg_flagged = ctx->mailbox->msg_flagged;
+ m->stats_last_checked = ctx->mailbox->mtime;
mx_mbox_close(&ctx, NULL);
}
}
*/
void mutt_mailbox_setnotified(const char *path)
{
- struct Mailbox *mailbox = mailbox_get(path);
- if (!mailbox)
+ struct Mailbox *m = mailbox_get(path);
+ if (!m)
return;
- mailbox->notified = true;
+ m->notified = true;
#if HAVE_CLOCK_GETTIME
- clock_gettime(CLOCK_REALTIME, &mailbox->last_visited);
+ clock_gettime(CLOCK_REALTIME, &m->last_visited);
#else
- mailbox->last_visited.tv_nsec = 0;
- time(&mailbox->last_visited.tv_sec);
+ m->last_visited.tv_nsec = 0;
+ time(&m->last_visited.tv_sec);
#endif
}
#endif
struct Mailbox *mailbox_new(const char *path);
-void mailbox_free(struct Mailbox **mailbox);
+void mailbox_free(struct Mailbox **m);
void mutt_context_free(struct Context **ctx);
struct Mailbox *mutt_find_mailbox(const char *path);
/**
* monitor_resolve - Get the monitor for a mailbox
- * @param[out] info Details of the mailbox's monitor
- * @param[in] mailbox Mailbox
+ * @param[out] info Details of the mailbox's monitor
+ * @param[in] m Mailbox
* @retval >=0 mailbox is valid and locally accessible:
* 0: no monitor / 1: preexisting monitor
* @retval -3 no mailbox (MonitorInfo: no fields set)
* @retval -2 magic not set
* @retval -1 stat() failed (see errno; MonitorInfo fields: magic, isdir, path)
*
- * If mailbox is NULL, the current mailbox (Context) is used.
+ * If m is NULL, the current mailbox (Context) is used.
*/
-static int monitor_resolve(struct MonitorInfo *info, struct Mailbox *mailbox)
+static int monitor_resolve(struct MonitorInfo *info, struct Mailbox *m)
{
struct Monitor *iter;
char *fmt = NULL;
struct stat sb;
- if (mailbox)
+ if (m)
{
- info->magic = mailbox->magic;
- info->path = mailbox->realpath;
+ info->magic = m->magic;
+ info->path = m->realpath;
}
else if (Context)
{
/**
* mutt_monitor_add - Add a watch for a mailbox
- * @param mailbox Mailbox to watch
+ * @param m Mailbox to watch
* @retval 0 success: new or already existing monitor
* @retval -1 failed: no mailbox, inaccessible file, create monitor/watcher failed
*
* If mailbox is NULL, the current mailbox (Context) is used.
*/
-int mutt_monitor_add(struct Mailbox *mailbox)
+int mutt_monitor_add(struct Mailbox *m)
{
struct MonitorInfo info;
- int desc = monitor_resolve(&info, mailbox);
+ int desc = monitor_resolve(&info, m);
if (desc != RESOLVERES_OK_NOTEXISTING)
{
- if (!mailbox && (desc == RESOLVERES_OK_EXISTING))
+ if (!m && (desc == RESOLVERES_OK_EXISTING))
MonitorContextDescriptor = info.monitor->desc;
return (desc == RESOLVERES_OK_EXISTING) ? 0 : -1;
}
}
mutt_debug(3, "inotify_add_watch descriptor=%d for '%s'\n", desc, info.path);
- if (!mailbox)
+ if (!m)
MonitorContextDescriptor = desc;
monitor_create(&info, desc);
/**
* mutt_monitor_remove - Remove a watch for a mailbox
- * @param mailbox Mailbox
+ * @param m Mailbox
* @retval 0 monitor removed (not shared)
* @retval 1 monitor not removed (shared)
* @retval 2 no monitor
*
* If mailbox is NULL, the current mailbox (Context) is used.
*/
-int mutt_monitor_remove(struct Mailbox *mailbox)
+int mutt_monitor_remove(struct Mailbox *m)
{
struct MonitorInfo info, info2;
- if (!mailbox)
+ if (!m)
{
MonitorContextDescriptor = -1;
MonitorContextChanged = 0;
}
- if (monitor_resolve(&info, mailbox) != RESOLVERES_OK_EXISTING)
+ if (monitor_resolve(&info, m) != RESOLVERES_OK_EXISTING)
return 2;
if (Context)
{
- if (mailbox)
+ if (m)
{
if ((monitor_resolve(&info2, NULL) == RESOLVERES_OK_EXISTING) &&
(info.st_ino == info2.st_ino) && (info.st_dev == info2.st_dev))
/**
* label_ref_dec - Decrease the refcount of a label
- * @param mailbox Mailbox
+ * @param m Mailbox
* @param label Label
*/
-static void label_ref_dec(struct Mailbox *mailbox, char *label)
+static void label_ref_dec(struct Mailbox *m, char *label)
{
- struct HashElem *elem = mutt_hash_find_elem(mailbox->label_hash, label);
+ struct HashElem *elem = mutt_hash_find_elem(m->label_hash, label);
if (!elem)
return;
uintptr_t count = (uintptr_t) elem->data;
if (count <= 1)
{
- mutt_hash_delete(mailbox->label_hash, label, NULL);
+ mutt_hash_delete(m->label_hash, label, NULL);
return;
}
/**
* label_ref_inc - Increase the refcount of a label
- * @param mailbox Mailbox
+ * @param m Mailbox
* @param label Label
*/
-static void label_ref_inc(struct Mailbox *mailbox, char *label)
+static void label_ref_inc(struct Mailbox *m, char *label)
{
uintptr_t count;
- struct HashElem *elem = mutt_hash_find_elem(mailbox->label_hash, label);
+ struct HashElem *elem = mutt_hash_find_elem(m->label_hash, label);
if (!elem)
{
count = 1;
- mutt_hash_insert(mailbox->label_hash, label, (void *) count);
+ mutt_hash_insert(m->label_hash, label, (void *) count);
return;
}
/**
* label_message - add an X-Label: field
- * @param[in] mailbox Mailbox
- * @param[in] e Email
+ * @param[in] m Mailbox
+ * @param[in] e Email
* @param[out] new Set to true if this is a new label
* @retval true If the label was added
*/
-static bool label_message(struct Mailbox *mailbox, struct Email *e, char *new)
+static bool label_message(struct Mailbox *m, struct Email *e, char *new)
{
if (!e)
return false;
return false;
if (e->env->x_label)
- label_ref_dec(mailbox, e->env->x_label);
+ label_ref_dec(m, e->env->x_label);
mutt_str_replace(&e->env->x_label, new);
if (e->env->x_label)
- label_ref_inc(mailbox, e->env->x_label);
+ label_ref_inc(m, e->env->x_label);
e->changed = true;
e->xlabel_changed = true;
/**
* mutt_make_label_hash - Create a Hash Table to store the labels
- * @param mailbox Mailbox
+ * @param m Mailbox
*/
-void mutt_make_label_hash(struct Mailbox *mailbox)
+void mutt_make_label_hash(struct Mailbox *m)
{
/* 131 is just a rough prime estimate of how many distinct
- * labels someone might have in a mailbox.
+ * labels someone might have in a m.
*/
- mailbox->label_hash = mutt_hash_create(131, MUTT_HASH_STRDUP_KEYS);
+ m->label_hash = mutt_hash_create(131, MUTT_HASH_STRDUP_KEYS);
}
/**
* mutt_label_hash_add - Add a message's labels to the Hash Table
- * @param mailbox Mailbox
+ * @param m Mailbox
* @param e Header of message
*/
-void mutt_label_hash_add(struct Mailbox *mailbox, struct Email *e)
+void mutt_label_hash_add(struct Mailbox *m, struct Email *e)
{
- if (!mailbox || !mailbox->label_hash)
+ if (!m || !m->label_hash)
return;
if (e->env->x_label)
- label_ref_inc(mailbox, e->env->x_label);
+ label_ref_inc(m, e->env->x_label);
}
/**
* mutt_label_hash_remove - Rmove a message's labels from the Hash Table
- * @param mailbox Mailbox
+ * @param m Mailbox
* @param e Header of message
*/
-void mutt_label_hash_remove(struct Mailbox *mailbox, struct Email *e)
+void mutt_label_hash_remove(struct Mailbox *m, struct Email *e)
{
- if (!mailbox || !mailbox->label_hash)
+ if (!m || !m->label_hash)
return;
if (e->env->x_label)
- label_ref_dec(mailbox, e->env->x_label);
+ label_ref_dec(m, e->env->x_label);
}
struct Email;
void mutt_edit_headers(const char *editor, const char *body, struct Email *msg, char *fcc, size_t fcclen);
-void mutt_label_hash_add(struct Mailbox *mailbox, struct Email *e);
-void mutt_label_hash_remove(struct Mailbox *mailbox, struct Email *e);
+void mutt_label_hash_add(struct Mailbox *m, struct Email *e);
+void mutt_label_hash_remove(struct Mailbox *m, struct Email *e);
int mutt_label_message(struct Email *e);
-void mutt_make_label_hash(struct Mailbox *mailbox);
+void mutt_make_label_hash(struct Mailbox *m);
#endif /* MUTT_MUTT_HEADER_H */
/**
* mutt_make_id_hash - Create a Hash Table for message-ids
- * @param mailbox Mailbox
+ * @param m Mailbox
* @retval ptr Newly allocated Hash Table
*/
-struct Hash *mutt_make_id_hash(struct Mailbox *mailbox)
+struct Hash *mutt_make_id_hash(struct Mailbox *m)
{
- struct Hash *hash = mutt_hash_create(mailbox->msg_count * 2, 0);
+ struct Hash *hash = mutt_hash_create(m->msg_count * 2, 0);
- for (int i = 0; i < mailbox->msg_count; i++)
+ for (int i = 0; i < m->msg_count; i++)
{
- struct Email *e = mailbox->hdrs[i];
+ struct Email *e = m->hdrs[i];
if (e->env->message_id)
mutt_hash_insert(hash, e->env->message_id, e);
}
void mutt_sort_threads(struct Context *ctx, bool init);
int mutt_parent_message(struct Context *ctx, struct Email *e, bool find_root);
void mutt_set_virtual(struct Context *ctx);
-struct Hash *mutt_make_id_hash(struct Mailbox *mailbox);
+struct Hash *mutt_make_id_hash(struct Mailbox *m);
#endif /* MUTT_MUTT_THREAD_H */
/**
* mx_alloc_memory - Create storage for the emails
- * @param mailbox Mailbox
+ * @param m Mailbox
*/
-void mx_alloc_memory(struct Mailbox *mailbox)
+void mx_alloc_memory(struct Mailbox *m)
{
size_t s = MAX(sizeof(struct Email *), sizeof(int));
- if ((mailbox->hdrmax + 25) * s < mailbox->hdrmax * s)
+ if ((m->hdrmax + 25) * s < m->hdrmax * s)
{
mutt_error(_("Out of memory"));
mutt_exit(1);
}
- if (mailbox->hdrs)
+ if (m->hdrs)
{
- mutt_mem_realloc(&mailbox->hdrs, sizeof(struct Email *) * (mailbox->hdrmax += 25));
- mutt_mem_realloc(&mailbox->v2r, sizeof(int) * mailbox->hdrmax);
+ mutt_mem_realloc(&m->hdrs, sizeof(struct Email *) * (m->hdrmax += 25));
+ mutt_mem_realloc(&m->v2r, sizeof(int) * m->hdrmax);
}
else
{
- mailbox->hdrs = mutt_mem_calloc((mailbox->hdrmax += 25), sizeof(struct Email *));
- mailbox->v2r = mutt_mem_calloc(mailbox->hdrmax, sizeof(int));
+ m->hdrs = mutt_mem_calloc((m->hdrmax += 25), sizeof(struct Email *));
+ m->v2r = mutt_mem_calloc(m->hdrmax, sizeof(int));
}
- for (int i = mailbox->msg_count; i < mailbox->hdrmax; i++)
+ for (int i = m->msg_count; i < m->hdrmax; i++)
{
- mailbox->hdrs[i] = NULL;
- mailbox->v2r[i] = -1;
+ m->hdrs[i] = NULL;
+ m->v2r[i] = -1;
}
}
int mx_tags_edit (struct Context *ctx, const char *tags, char *buf, size_t buflen);
int mx_access(const char *path, int flags);
-void mx_alloc_memory(struct Mailbox *mailbox);
+void mx_alloc_memory(struct Mailbox *m);
int mx_check_empty(const char *path);
int mx_check_mailbox(struct Context *ctx, int *index_hint);
void mx_fastclose_mailbox(struct Context *ctx);