#include <dirent.h>
#include <utime.h>
+#include <lib-lua/lib-lua.h>
#include <lib-ui/curses.h>
#include <lib-ui/sidebar.h>
#include <lib-mx/mx.h>
#include "mutt.h"
#include "buffy.h"
+@import "lib-lua/base.cpkg"
static time_t BuffyTime = 0; /* last time we started checking for mail */
static time_t ImapBuffyTime = 0; /* last time we started checking for mail */
static short BuffyCount = 0; /* how many boxes with new mail */
static short BuffyNotify = 0; /* # of unnotified new boxes */
+buffy_array Incoming;
-/* Return the index number of path in Incoming list */
-int buffy_lookup(const char* path)
-{
- int i;
+@package Buffy {
+ /*
+ ** .pp
+ ** This variable configures how often (in seconds) Madmutt should look for
+ ** new mail.
+ ** .pp
+ ** \fBNote:\fP This does not apply to IMAP mailboxes, see $$imap_mail_check.
+ */
+ int mail_check = 5;
- if (m_strisempty(path))
- return -1;
+ void mailboxes(const string_t s) {
+ buffy_do_mailboxes(s, 1);
+ RETURN();
+ };
- for (i = 0; i < Incoming.len; i++) {
- if (!m_strcmp(Incoming.arr[i]->path, path))
- return i;
- }
+ void unmailboxes(const string_t s) {
+ buffy_do_mailboxes(s, 0);
+ RETURN();
+ };
+};
- return -1;
-}
-
-int buffy_parse_mailboxes(BUFFER *path, BUFFER *s, unsigned long data,
- BUFFER *err __attribute__ ((unused)))
+void buffy_do_mailboxes(const char *s, int add)
{
- BUFFY *tmp;
char buf[_POSIX_PATH_MAX];
+ BUFFY *tmp;
+ int i;
- while (MoreArgs(s)) {
- int i;
+ if (!m_strcmp(s, "*")) {
+ buffy_array_wipe(&Incoming);
+ return;
+ }
- mutt_extract_token(path, s, 0);
- m_strcpy(buf, sizeof(buf), path->data);
+ if (m_strisempty(s))
+ return;
- if (data == M_UNMAILBOXES && !m_strcmp(buf, "*")) {
- buffy_array_wipe(&Incoming);
- return 0;
- }
+ _mutt_expand_path(buf, sizeof(buf), s, 0);
+ i = buffy_lookup(buf);
- /* Skip empty tokens. */
- if (!*buf)
- continue;
+ if (!add) {
+ tmp = buffy_array_take(&Incoming, i);
+ buffy_delete(&tmp);
+ return;
+ }
- mutt_expand_path(buf, sizeof (buf));
- i = buffy_lookup(buf);
+ if (i < 0) {
+ tmp = p_new(BUFFY, 1);
+ tmp->path = m_strdup(buf);
+ buffy_array_append(&Incoming, tmp);
+ } else {
+ tmp = Incoming.arr[i];
+ }
- if (data == M_UNMAILBOXES) {
- tmp = buffy_array_take(&Incoming, i);
- buffy_delete(&tmp);
- continue;
- }
+ tmp->new = 0;
+ tmp->notified = 1;
+ tmp->newly_created = 0;
+}
- if (i < 0) {
- tmp = p_new(BUFFY, 1);
- tmp->path = m_strdup(buf);
- buffy_array_append(&Incoming, tmp);
- } else {
- tmp = Incoming.arr[i];
- }
+/* Return the index number of path in Incoming list */
+int buffy_lookup(const char* path)
+{
+ int i;
- tmp->new = 0;
- tmp->notified = 1;
- tmp->newly_created = 0;
+ if (m_strisempty(path))
+ return -1;
+
+ for (i = 0; i < Incoming.len; i++) {
+ if (!m_strcmp(Incoming.arr[i]->path, path))
+ return i;
}
- return 0;
+ return -1;
}
#define STAT_CHECK (sb.st_mtime > sb.st_atime || (tmp->newly_created && sb.st_ctime == sb.st_mtime && sb.st_ctime == sb.st_atime))
return 0;
now = time (NULL);
- if (force == 0 && (now - BuffyTime < BuffyTimeout)
+ if (force == 0 && (now - BuffyTime < Buffy.mail_check)
&& (now - ImapBuffyTime < ImapBuffyTimeout))
return BuffyCount;
last1 = BuffyTime;
- if (force == 1 || now - BuffyTime >= BuffyTimeout)
+ if (force == 1 || now - BuffyTime >= Buffy.mail_check)
BuffyTime = now;
last2 = ImapBuffyTime;
if (force == 1 || now - ImapBuffyTime >= ImapBuffyTimeout)
case M_MBOX:
case M_MMDF:
/* only check on force or $mail_check reached */
- if (force == 1 || (now - last1 >= BuffyTimeout)) {
+ if (force == 1 || (now - last1 >= Buffy.mail_check)) {
if (!count) {
if (STAT_CHECK) {
BuffyCount++;
case M_MAILDIR:
/* only check on force or $mail_check reached */
- if (force == 1 || (now - last1 >= BuffyTimeout)) {
+ if (force == 1 || (now - last1 >= Buffy.mail_check)) {
snprintf (path, sizeof (path), "%s/new", tmp->path);
if ((dirp = opendir (path)) == NULL) {
tmp->magic = 0;
case M_MH:
/* only check on force or $mail_check reached */
- if (force == 1 || (now - last1 >= BuffyTimeout)) {
+ if (force == 1 || (now - last1 >= Buffy.mail_check)) {
if ((tmp->new = mh_buffy (tmp->path)) > 0)
BuffyCount++;
if (count) {
mutt_pretty_mailbox(s);
}
}
+
+/* vim:set ft=c: */
DO_ARRAY_TYPE(BUFFY, buffy);
DO_ARRAY_FUNCS(BUFFY, buffy, buffy_delete);
+#include "buffy.li"
+
/* folders with incomming mail (via mailboxes command) */
-WHERE buffy_array Incoming;
-WHERE short BuffyTimeout INITVAL (3);
-extern time_t BuffyDoneTime; /* last time we knew for sure how much mail there was */
+extern buffy_array Incoming;
-/* looks up a path in Incoming list (returns index) */
int buffy_lookup (const char*);
-/* handles mailboxes commands */
-int buffy_parse_mailboxes (BUFFER*, BUFFER*, unsigned long, BUFFER*);
+void buffy_do_mailboxes(const char *s, int add);
+
/* from given path, gets next mailbox in Incoming with new mail */
void buffy_next (char*, size_t);
/* checks mailboxes for new mail (returns number) */
#include <lib-mx/mx.h>
#include "mutt.h"
+#include "buffy.h"
#include "message.h"
#include "imap_private.h"
static void cmd_parse_lsub (IMAP_DATA* idata, char* s) {
char buf[STRING];
- char errstr[STRING];
- BUFFER err, token;
ciss_url_t url;
char *ep;
if (s) {
imap_unmunge_mbox_name (s);
- m_strcpy(buf, sizeof(buf), "mailboxes \"");
- mutt_account_tourl (&idata->conn->account, &url);
+ mutt_account_tourl(&idata->conn->account, &url);
url.path = s;
if (!m_strcmp(url.user, ImapUser))
url.user = NULL;
- url_ciss_tostring (&url, buf + 11, sizeof (buf) - 10, 0);
- m_strcat(buf, sizeof(buf), "\"");
- p_clear(&token, 1);
- err.data = errstr;
- err.dsize = sizeof (errstr);
- mutt_parse_rc_line (buf, &token, &err);
- p_delete(&token.data);
+ url_ciss_tostring(&url, buf, sizeof(buf), 0);
+ buffy_do_mailboxes(buf, 1);
}
}
# include "sort.h"
#endif
-#include "buffy.h"
#include "mutt.h"
#ifndef _MAKEDOC
** to this length. A value of 0 (which is also the default) means that the
** maximum line length is determined by the terminal width and $$wrapmargin.
*/
- {"mail_check", DT_NUM, R_NONE, UL &BuffyTimeout, "5" },
- /*
- ** .pp
- ** This variable configures how often (in seconds) Madmutt should look for
- ** new mail.
- ** .pp
- ** \fBNote:\fP This does not apply to IMAP mailboxes, see $$imap_mail_check.
- */
#ifdef USE_HCACHE
{"header_cache", DT_PATH, R_NONE, UL &HeaderCache, "" },
/*
};
struct command_t Commands[] = {
- {"mailboxes", buffy_parse_mailboxes, M_MAILBOXES},
- {"unmailboxes", buffy_parse_mailboxes, M_UNMAILBOXES},
{"bind", mutt_parse_bind, 0},
{"color", mutt_parse_color, 0},
{"exec", mutt_parse_exec, 0},