}
+// /ctdl/a/biff returns the number of new messages that have arrived in the inbox
+// since the beginning of the session or since the last call to biff
+void biff(struct http_transaction *h, struct ctdlsession *c) {
+ char biffbuff[1024];
+
+ ctdl_printf(c, "BIFF"); // send the command
+ ctdl_readline(c, biffbuff, sizeof(biffbuff)); // read the result
+ h->response_code = 200;
+ h->response_string = strdup("OK");
+ add_response_header(h, strdup("Content-type"), strdup("text/plain"));
+ h->response_body = strdup(&biffbuff[4]);
+ h->response_body_length = strlen(h->response_body);
+}
+
+
// Dispatcher for paths starting with /ctdl/a/
void ctdl_a(struct http_transaction *h, struct ctdlsession *c) {
if (!strcasecmp(h->url, "/ctdl/a/login")) { // log in
return;
}
+ if (!strcasecmp(h->url, "/ctdl/a/biff")) { // check for new messages in the inbox
+ biff(h, c);
+ return;
+ }
+
do_404(h); // unknown
}
var can_delete_messages = 0;
var messages_per_page = 20;
var march_list = [] ;
+var new_mail = 0;
// List of defined views shamelessly swiped from libcitadel headers
// When the user elects to log out, we just call /ctdl/a/logout and let the system flush the session.
// When we go back to ctdl_startup() it will detect that we are no longer logged in, and do the right thing.
//function logout() {
-logout = async() => {
- response = await fetch("/ctdl/a/logout");
- ctdl_startup(); // let the regular startup code take care of everything else
-}
+//logout = async() => {
+ //response = await fetch("/ctdl/a/logout");
+ //ctdl_startup(); // let the regular startup code take care of everything else
+//}
function login_button(username) {
// disclosure are subject to the GNU General Public License v3.
+do_biff = async() => {
+ response = await fetch("/ctdl/a/biff");
+ if (response.ok) {
+ biff_result = await(response.text());
+ try {
+ new_mail += parseInt(biff_result);
+ }
+ catch {
+ }
+ }
+
+ if (new_mail > 0) {
+ console.log("YOU'VE GOT MAIL!");
+ new_mail_sound.play(); // FIXME do a visual notification as well
+ new_mail = 0;
+ }
+}
+
+
// This is called at the very beginning of the main page load.
ctdl_startup = async() => {
+ var BiffInterval;
response = await fetch("/ctdl/c/info");
if (response.ok) {
else { // Otherwise,
display_login_screen(""); // display the login modal.
}
+
+ var BiffInterval;
+ try { // if this was already set up, clear it so there aren't multiple
+ clearInterval(BiffInterval);
+ }
+ catch {
+ }
+ do_biff();
+ BiffInterval = setInterval(do_biff, 10000);
}
else {
document.getElementById("ctdl-main").innerHTML =
if (selected_message > 0) { // if we had a message selected, keep it selected
select_message(selected_message);
}
-
-
-
-
-/*
- if ( (do_notify > 0) && (notify == newmail_notify.YES) ) {
- console.log(do_notify + " new mail");
- new_mail_sound.play(); // FIXME do a visual notification as well
- // FIXME move this to BIFF
- }
- */
-
-
-
}
}
fetch_mailbox();