#endif
/* imap forward declarations */
-static char *imap_get_flags(struct List **hflags, char *s);
+static char *imap_get_flags(struct STailQHead *hflags, char *s);
static int imap_check_capabilities(struct ImapData *idata);
static void imap_set_flag(struct ImapData *idata, int aclbit, int flag,
const char *str, char *flags, size_t flsize);
*
* return stream following FLAGS response
*/
-static char *imap_get_flags(struct List **hflags, char *s)
+static char *imap_get_flags(struct STailQHead *hflags, char *s)
{
- struct List *flags = NULL;
char *flag_word = NULL;
char ctmp;
return NULL;
}
- /* create list, update caller's flags handle */
- flags = mutt_new_list();
- *hflags = flags;
-
+ /* update caller's flags handle */
while (*s && *s != ')')
{
s++;
ctmp = *s;
*s = '\0';
if (*flag_word)
- mutt_add_list(flags, flag_word);
+ mutt_stailq_insert_tail(hflags, safe_strdup(flag_word));
*s = ctmp;
}
if (*s != ')')
{
mutt_debug(1, "imap_get_flags: Unterminated FLAGS response: %s\n", s);
- mutt_free_list(hflags);
+ mutt_stailq_free(hflags);
return NULL;
}
if (mutt_strncasecmp("FLAGS", pc, 5) == 0)
{
/* don't override PERMANENTFLAGS */
- if (!idata->flags)
+ if (STAILQ_EMPTY(&idata->flags))
{
mutt_debug(3, "Getting mailbox FLAGS\n");
- if ((pc = imap_get_flags(&(idata->flags), pc)) == NULL)
+ if ((pc = imap_get_flags(&idata->flags, pc)) == NULL)
goto fail;
}
}
{
mutt_debug(3, "Getting mailbox PERMANENTFLAGS\n");
/* safe to call on NULL */
- mutt_free_list(&(idata->flags));
+ mutt_stailq_free(&idata->flags);
/* skip "OK [PERMANENT" so syntax is the same as FLAGS */
pc += 13;
if ((pc = imap_get_flags(&(idata->flags), pc)) == NULL)
/* dump the mailbox flags we've found */
if (debuglevel > 2)
{
- if (!idata->flags)
+ if (STAILQ_EMPTY(&idata->flags))
mutt_debug(3, "No folder flags found\n");
else
{
- struct List *t = idata->flags;
-
mutt_debug(3, "Mailbox flags: ");
-
- t = t->next;
- while (t)
+ struct STailQNode *np;
+ STAILQ_FOREACH(np, &idata->flags, entries)
{
- mutt_debug(3, "[%s] ", t->data);
- t = t->next;
+ mutt_debug(3, "[%s] ", np->data);
}
mutt_debug(3, "\n");
}
const char *str, char *flags, size_t flsize)
{
if (mutt_bit_isset(idata->ctx->rights, aclbit))
- if (flag && imap_has_flag(idata->flags, str))
+ if (flag && imap_has_flag(&idata->flags, str))
safe_strcat(flags, flsize, str);
}
* Do a caseless comparison of the flag against a flag list, return true if
* found or flag list has '\*'.
*/
-bool imap_has_flag(struct List *flag_list, const char *flag)
+bool imap_has_flag(struct STailQHead *flag_list, const char *flag)
{
- if (!flag_list)
+ if (STAILQ_EMPTY(flag_list))
return false;
- flag_list = flag_list->next;
- while (flag_list)
+ struct STailQNode *np;
+ STAILQ_FOREACH(np, flag_list, entries)
{
- if (mutt_strncasecmp(flag_list->data, flag, strlen(flag_list->data)) == 0)
+ if (mutt_strncasecmp(np->data, flag, strlen(np->data)) == 0)
return true;
- if (mutt_strncmp(flag_list->data, "\\*", strlen(flag_list->data)) == 0)
+ if (mutt_strncmp(np->data, "\\*", strlen(np->data)) == 0)
return true;
-
- flag_list = flag_list->next;
}
return false;
/* now make sure we don't lose custom tags */
if (mutt_bit_isset(idata->ctx->rights, MUTT_ACL_WRITE))
- imap_add_keywords(flags, hdr, idata->flags, sizeof(flags));
+ imap_add_keywords(flags, hdr, &idata->flags, sizeof(flags));
mutt_remove_trailing_ws(flags);
if (!mutt_bit_isset(idata->ctx->rights, right))
return 0;
- if (right == MUTT_ACL_WRITE && !imap_has_flag(idata->flags, name))
+ if (right == MUTT_ACL_WRITE && !imap_has_flag(&idata->flags, name))
return 0;
snprintf(buf, sizeof(buf), "+FLAGS.SILENT (%s)", name);
idata->reopen &= IMAP_REOPEN_ALLOW;
FREE(&(idata->mailbox));
- mutt_free_list(&idata->flags);
+ mutt_stailq_free(&idata->flags);
idata->ctx = NULL;
hash_destroy(&idata->uid_hash, NULL);
*/
struct ImapStatus *imap_mboxcache_get(struct ImapData *idata, const char *mbox, int create)
{
- struct List *cur = NULL;
struct ImapStatus *status = NULL;
- struct ImapStatus scache;
#ifdef USE_HCACHE
header_cache_t *hc = NULL;
void *uidvalidity = NULL;
void *uidnext = NULL;
#endif
- for (cur = idata->mboxcache; cur; cur = cur->next)
+ struct STailQNode *np;
+ STAILQ_FOREACH(np, &idata->mboxcache, entries)
{
- status = (struct ImapStatus *) cur->data;
+ status = (struct ImapStatus *) np->data;
if (imap_mxcmp(mbox, status->name) == 0)
return status;
/* lame */
if (create)
{
- memset(&scache, 0, sizeof(scache));
- scache.name = (char *) mbox;
- idata->mboxcache = mutt_add_list_n(idata->mboxcache, &scache, sizeof(scache));
+ struct ImapStatus *scache = safe_calloc(1, sizeof(struct ImapStatus));
+ scache->name = (char *) mbox;
+ mutt_stailq_insert_tail(&idata->mboxcache, (char *)scache);
status = imap_mboxcache_get(idata, mbox, 0);
status->name = safe_strdup(mbox);
}
void imap_mboxcache_free(struct ImapData *idata)
{
- struct List *cur = NULL;
struct ImapStatus *status = NULL;
- for (cur = idata->mboxcache; cur; cur = cur->next)
+ struct STailQNode *np;
+ STAILQ_FOREACH(np, &idata->mboxcache, entries)
{
- status = (struct ImapStatus *) cur->data;
-
+ status = (struct ImapStatus *) np->data;
FREE(&status->name);
}
- mutt_free_list(&idata->mboxcache);
+ mutt_stailq_free(&idata->mboxcache);
}
/**
#ifdef USE_HCACHE
#include "hcache/hcache.h"
#endif
+#include "list.h"
struct Account;
struct Buffer;
struct Header;
struct ImapHeaderData;
struct ImapMbox;
-struct List;
struct Message;
struct Progress;
struct Buffer *cmdbuf;
/* cache ImapStatus of visited mailboxes */
- struct List *mboxcache;
+ struct STailQHead mboxcache;
/* The following data is all specific to the currently SELECTED mbox */
char delim;
struct BodyCache *bcache;
/* all folder flags - system flags AND keywords */
- struct List *flags;
+ struct STailQHead flags;
#ifdef USE_HCACHE
header_cache_t *hcache;
#endif
void imap_expunge_mailbox(struct ImapData *idata);
void imap_logout(struct ImapData **idata);
int imap_sync_message(struct ImapData *idata, struct Header *hdr, struct Buffer *cmd, int *err_continue);
-bool imap_has_flag(struct List *flag_list, const char *flag);
+bool imap_has_flag(struct STailQHead *flag_list, const char *flag);
/* auth.c */
int imap_authenticate(struct ImapData *idata);
int imap_cmd_idle(struct ImapData *idata);
/* message.c */
-void imap_add_keywords(char *s, struct Header *keywords, struct List *mailbox_flags, size_t slen);
+void imap_add_keywords(char *s, struct Header *keywords, struct STailQHead *mailbox_flags, size_t slen);
void imap_free_header_data(struct ImapHeaderData **data);
int imap_read_headers(struct ImapData *idata, unsigned int msn_begin, unsigned int msn_end);
char *imap_set_flags(struct ImapData *idata, struct Header *h, char *s);
#include "hcache/hcache.h"
#endif
+static struct ImapHeaderData* imap_new_header_data(void)
+{
+ struct ImapHeaderData *d = safe_calloc(1, sizeof(struct ImapHeaderData));
+ STAILQ_INIT(&d->keywords);
+ return d;
+}
+
static void imap_update_context(struct ImapData *idata, int oldmsgcount)
{
struct Context *ctx = NULL;
}
s++;
- mutt_free_list(&hd->keywords);
+ mutt_stailq_free(&hd->keywords);
hd->deleted = hd->flagged = hd->replied = hd->read = hd->old = false;
/* start parsing */
char ctmp;
char *flag_word = s;
- if (!hd->keywords)
- hd->keywords = mutt_new_list();
-
while (*s && !ISSPACE(*s) && *s != ')')
s++;
ctmp = *s;
*s = '\0';
- mutt_add_list(hd->keywords, flag_word);
+ mutt_stailq_insert_tail(&hd->keywords, safe_strdup(flag_word));
*s = ctmp;
}
SKIPWS(s);
mutt_progress_update(&progress, msgno, -1);
memset(&h, 0, sizeof(h));
- h.data = safe_calloc(1, sizeof(struct ImapHeaderData));
+ h.data = imap_new_header_data();
do
{
rc = imap_cmd_step(idata);
rewind(fp);
memset(&h, 0, sizeof(h));
- h.data = safe_calloc(1, sizeof(struct ImapHeaderData));
+ h.data = imap_new_header_data();
/* this DO loop does two things:
* 1. handles untagged messages, so we can try again on the same msg
*
* If the tags appear in the folder flags list. Why wouldn't they?
*/
-void imap_add_keywords(char *s, struct Header *h, struct List *mailbox_flags, size_t slen)
+void imap_add_keywords(char *s, struct Header *h, struct STailQHead *mailbox_flags, size_t slen)
{
- struct List *keywords = NULL;
+ struct STailQHead *keywords = &HEADER_DATA(h)->keywords;
- if (!mailbox_flags || !HEADER_DATA(h) || !HEADER_DATA(h)->keywords)
+ if (STAILQ_EMPTY(mailbox_flags) || !HEADER_DATA(h) || STAILQ_EMPTY(keywords))
return;
- keywords = HEADER_DATA(h)->keywords->next;
-
- while (keywords)
+ struct STailQNode *np;
+ STAILQ_FOREACH(np, keywords, entries)
{
- if (imap_has_flag(mailbox_flags, keywords->data))
+ if (imap_has_flag(mailbox_flags, np->data))
{
- safe_strcat(s, slen, keywords->data);
+ safe_strcat(s, slen, np->data);
safe_strcat(s, slen, " ");
}
- keywords = keywords->next;
}
}
if (*data)
{
/* this should be safe even if the list wasn't used */
- mutt_free_list(&((*data)->keywords));
+ mutt_stailq_free(&(*data)->keywords);
FREE(data);
}
}