From: Pierre Habouzit Date: Sat, 31 Mar 2007 13:17:53 +0000 (+0200) Subject: Make buffy a lua package as well. X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=commitdiff_plain;h=c9f72ab0cd65f517a2047feb942ad85025c1b7e8 Make buffy a lua package as well. Signed-off-by: Pierre Habouzit --- diff --git a/buffy.c b/buffy.cpkg similarity index 88% rename from buffy.c rename to buffy.cpkg index 6c9ef3e..5ea4188 100644 --- a/buffy.c +++ b/buffy.cpkg @@ -14,6 +14,7 @@ #include #include +#include #include #include #include @@ -23,72 +24,85 @@ #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)) @@ -118,12 +132,12 @@ int buffy_check(int force) 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) @@ -161,7 +175,7 @@ int buffy_check(int force) 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++; @@ -191,7 +205,7 @@ int buffy_check(int force) 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; @@ -250,7 +264,7 @@ int buffy_check(int force) 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) { @@ -404,3 +418,5 @@ void buffy_next(char *s, size_t slen) mutt_pretty_mailbox(s); } } + +/* vim:set ft=c: */ diff --git a/buffy.h b/buffy.h index fdd2ca3..625ade8 100644 --- a/buffy.h +++ b/buffy.h @@ -35,15 +35,14 @@ DO_DELETE(BUFFY, buffy); 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) */ diff --git a/imap/command.c b/imap/command.c index bf21c4b..c33776b 100644 --- a/imap/command.c +++ b/imap/command.c @@ -16,6 +16,7 @@ #include #include "mutt.h" +#include "buffy.h" #include "message.h" #include "imap_private.h" @@ -485,8 +486,6 @@ static void cmd_parse_fetch (IMAP_DATA * idata, char *s) 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; @@ -517,18 +516,12 @@ static void cmd_parse_lsub (IMAP_DATA* idata, char* s) { 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); } } diff --git a/init.h b/init.h index 7174182..86271da 100644 --- a/init.h +++ b/init.h @@ -17,7 +17,6 @@ # include "sort.h" #endif -#include "buffy.h" #include "mutt.h" #ifndef _MAKEDOC @@ -1097,14 +1096,6 @@ struct option_t MuttVars[] = { ** 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, "" }, /* @@ -3400,8 +3391,6 @@ struct command_t { }; 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}, diff --git a/lib-lua/lua-token.sh b/lib-lua/lua-token.sh index 110e565..a5606e6 100644 --- a/lib-lua/lua-token.sh +++ b/lib-lua/lua-token.sh @@ -132,6 +132,7 @@ exit 0 ## hostname ## mailcap_path ## mailcap_sanitize +## mail_check ## no ## operating_system ## quit diff --git a/lib-lua/runtime.c b/lib-lua/runtime.c index 1e806c4..6023ae6 100644 --- a/lib-lua/runtime.c +++ b/lib-lua/runtime.c @@ -23,6 +23,7 @@ #include "../alias.h" #include "../mutt.h" #include "../charset.h" +#include "../buffy.h" static lua_State *L; @@ -42,6 +43,7 @@ void luaM_initialize(void) {"MAlias", luaopen_MAlias}, {"MCharset", luaopen_MCharset}, {"Mime", luaopen_Mime}, + {"Buffy", luaopen_Buffy}, }; int i; diff --git a/tools/Makefile b/tools/Makefile index 1ae72cc..2a279aa 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -3,7 +3,8 @@ all: ../lib-mime/mime-token.h \ ../lib-mime/mime.li \ ../lib-lua/lua-token.h \ ../lib-lua/madmutt.li \ - ../charset.li + ../charset.li \ + ../buffy.li ../%: ; $(MAKE) -C $(@D) $(@F)