Added code for persisting email read/deleted status in EMAIL.DB

This commit is contained in:
Bobbi Webber-Manners 2020-06-25 23:18:23 -04:00
parent 872c5c3339
commit 4a2a942365

View File

@ -5,11 +5,11 @@
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// TODO: // TODO:
// - Saving updated email status -> EMAIL.DB
// - Purging deleted emails // - Purging deleted emails
// - Switching folders // - Switching folders
// - Moving & copying emails between folders // - Moving & copying emails between folders
// - Email composition (new message, reply and forward) // - Email composition (new message, reply and forward)
// - Better error handling (maybe just clear screen before fatal error?)
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@ -242,15 +242,13 @@ void email_pager(void) {
cgetc(); cgetc();
return; return;
} }
h->status = 'R'; // Mark email read
--total_new;
pos = h->skipbytes; pos = h->skipbytes;
fseek(fp, pos, SEEK_SET); // Skip over headers fseek(fp, pos, SEEK_SET); // Skip over headers
restart: restart:
clrscr(); clrscr();
line = 6; line = 6;
fputs("Date: ", stdout); fputs("Date: ", stdout);
printfield(h->date, 0, 70); printfield(h->date, 0, 39);
fputs("\nFrom: ", stdout); fputs("\nFrom: ", stdout);
printfield(h->from, 0, 70); printfield(h->from, 0, 70);
fputs("\nTo: ", stdout); fputs("\nTo: ", stdout);
@ -359,6 +357,29 @@ retry2:
} }
} }
/*
* Write updated email headers to EMAIL.DB
*/
void write_updated_headers(struct emailhdrs *h, uint16_t pos) {
uint16_t l;
sprintf(filename, "%s/EMAIL.DB", cfg_inboxdir);
fp = fopen(filename, "rb+");
if (!fp) {
printf("Can't open %s\n", filename);
error_exit();
}
if (fseek(fp, (pos - 1) * (sizeof(struct emailhdrs) - 2), SEEK_SET)) {
printf("Can't seek in %s\n", filename);
error_exit();
}
l = fwrite(h, 1, sizeof(struct emailhdrs) - 2, fp);
if (l != sizeof(struct emailhdrs) - 2) {
printf("Can't write to %s\n", filename);
error_exit();
}
fclose(fp);
}
/* /*
* Keyboard handler * Keyboard handler
*/ */
@ -397,22 +418,33 @@ void keyboard_hdlr(void) {
break; break;
case 0x0d: // RETURN case 0x0d: // RETURN
case ' ': case ' ':
h = get_headers(selection);
if (h) {
if (h->status == 'N')
--total_new;
h->status = 'R'; // Mark email read
write_updated_headers(h, first_msg + selection - 1);
}
email_pager(); email_pager();
email_summary(); email_summary();
break; break;
case 'd': case 'd':
case 'D': case 'D':
h = get_headers(selection); h = get_headers(selection);
if (h) if (h) {
h->status = 'D'; h->status = 'D';
write_updated_headers(h, first_msg + selection - 1);
email_summary_for(selection); email_summary_for(selection);
}
break; break;
case 'u': case 'u':
case 'U': case 'U':
h = get_headers(selection); h = get_headers(selection);
if (h) if (h) {
h->status = 'R'; h->status = 'R';
write_updated_headers(h, first_msg + selection - 1);
email_summary_for(selection); email_summary_for(selection);
}
break; break;
case 'p': case 'p':
case 'P': case 'P':