Initial support for reading multiple mboxes

This commit is contained in:
Bobbi Webber-Manners 2020-06-26 11:00:11 -04:00
parent 4a2a942365
commit 84cac8efd4
3 changed files with 38 additions and 19 deletions

View File

@ -20,7 +20,8 @@
#define EMAIL_C
#include "email_common.h"
#define MSGS_PER_PAGE 20 // Number of messages shown on summary screen
#define MSGS_PER_PAGE 18 // Number of messages shown on summary screen
#define MENU_ROW 23 // Row that the menu appears on
#define SCROLLBACK 25*80 // How many bytes to go back when paging up
char filename[80];
@ -31,6 +32,7 @@ uint16_t num_msgs; // Number of messages shown in current page
uint16_t total_msgs; // Total number of message in mailbox
uint16_t total_new; // Total number of new messages
uint16_t first_msg; // Message number of first message on current page
char curr_mbox[80] = "INBOX";
/*
* Keypress before quit
@ -60,8 +62,7 @@ void readconfigfile(void) {
fscanf(fp, "%s", cfg_server);
fscanf(fp, "%s", cfg_user);
fscanf(fp, "%s", cfg_pass);
fscanf(fp, "%s", cfg_spooldir);
fscanf(fp, "%s", cfg_inboxdir);
fscanf(fp, "%s", cfg_emaildir);
fclose(fp);
}
@ -90,7 +91,7 @@ void read_email_db(uint16_t startnum, uint8_t initialize) {
total_new = total_msgs = 0;
}
free_headers_list();
sprintf(filename, "%s/EMAIL.DB", cfg_inboxdir);
sprintf(filename, "%s/%s/EMAIL.DB", cfg_emaildir, curr_mbox);
fp = fopen(filename, "rb");
if (!fp) {
printf("Can't open %s\n", filename);
@ -189,8 +190,8 @@ void email_summary(void) {
uint8_t i = 1;
struct emailhdrs *h = headers;
clrscr();
printf("%c%u messages, %u new. Displaying %u-%u%c",
0x0f, total_msgs, total_new, first_msg,
printf("%c[%s] %u messages, %u new. Displaying %u-%u%c",
0x0f, curr_mbox, total_msgs, total_new, first_msg,
first_msg + num_msgs - 1, 0x0e);
printf("\n\n");
while (h) {
@ -199,7 +200,7 @@ void email_summary(void) {
h = h->next;
}
putchar(0x19); // HOME
for (i = 0; i < 23; ++i)
for (i = 0; i < MENU_ROW - 1; ++i)
putchar(0x0a); // CURSOR DOWN
printf("%cUp/K Prev | Down/J Next | SPACE/CR Read | D)elete | U)ndel | Q)uit%c", 0x0f, 0x0e);
}
@ -234,7 +235,7 @@ void email_pager(void) {
uint8_t line, eof;
char c;
clrscr();
sprintf(filename, "%s/EMAIL.%u", cfg_inboxdir, h->emailnum);
sprintf(filename, "%s/%s/EMAIL.%u", cfg_emaildir, curr_mbox, h->emailnum);
fp = fopen(filename, "rb");
if (!fp) {
printf("Can't open %s\n", filename);
@ -362,7 +363,7 @@ retry2:
*/
void write_updated_headers(struct emailhdrs *h, uint16_t pos) {
uint16_t l;
sprintf(filename, "%s/EMAIL.DB", cfg_inboxdir);
sprintf(filename, "%s/%s/EMAIL.DB", cfg_emaildir, curr_mbox);
fp = fopen(filename, "rb+");
if (!fp) {
printf("Can't open %s\n", filename);
@ -380,6 +381,17 @@ void write_updated_headers(struct emailhdrs *h, uint16_t pos) {
fclose(fp);
}
/*
* Change current mailbox
*/
void change_mailbox(char *mbox) {
strcpy(curr_mbox, mbox);
first_msg = 1;
read_email_db(first_msg, 1);
selection = 1;
email_summary();
}
/*
* Keyboard handler
*/
@ -450,6 +462,14 @@ void keyboard_hdlr(void) {
case 'P':
// TODO: Purge deleted messages
break;
case 'c':
case 'C':
// TODO: Prompt for mailbox
if (!strcmp(curr_mbox, "INBOX"))
change_mailbox("RECEIVED");
else
change_mailbox("INBOX");
break;
case 'q':
case 'Q':
clrscr();

View File

@ -8,8 +8,7 @@
char cfg_server[80]; // IP of POP3 server
char cfg_user[80]; // Username
char cfg_pass[80]; // Password
char cfg_spooldir[80]; // ProDOS directory to spool email to
char cfg_inboxdir[80]; // ProDOS directory for email inbox
char cfg_emaildir[80]; // ProDOS directory at root of email tree
// Represents the email headers for one message
struct emailhdrs {

View File

@ -7,6 +7,7 @@
/////////////////////////////////////////////////////////////////
// TODO: EMAIL.n files should be type TXT
// TODO: The way CRLF.CRLF is detected will not work if split across packets
#include <cc65.h>
#include <errno.h>
@ -294,8 +295,7 @@ void readconfigfile(void) {
fscanf(fp, "%s", cfg_server);
fscanf(fp, "%s", cfg_user);
fscanf(fp, "%s", cfg_pass);
fscanf(fp, "%s", cfg_spooldir);
fscanf(fp, "%s", cfg_inboxdir);
fscanf(fp, "%s", cfg_emaildir);
fclose(fp);
}
@ -338,7 +338,7 @@ int16_t get_line(FILE *fp) {
*/
void update_email_db(struct emailhdrs *h) {
FILE *fp;
sprintf(filename, "%s/EMAIL.DB", cfg_inboxdir);
sprintf(filename, "%s/INBOX/EMAIL.DB", cfg_emaildir);
fp = fopen(filename, "a");
if (!fp) {
printf("Can't open %s\n", filename);
@ -365,7 +365,7 @@ void copyheader(char *dest, char *source, uint16_t len) {
* Write NEXT.EMAIL file with number of next EMAIL.n file to be created
*/
void write_next_email(uint16_t num) {
sprintf(filename, "%s/NEXT.EMAIL", cfg_inboxdir);
sprintf(filename, "%s/INBOX/NEXT.EMAIL", cfg_emaildir);
fp = fopen(filename, "wb");
if (!fp) {
printf("Can't open %s\n", filename);
@ -386,7 +386,7 @@ void update_inbox(uint16_t nummsgs) {
uint16_t nextemail, msg, chars, headerchars;
uint8_t headers;
FILE *destfp;
sprintf(filename, "%s/NEXT.EMAIL", cfg_inboxdir);
sprintf(filename, "%s/INBOX/NEXT.EMAIL", cfg_emaildir);
fp = fopen(filename, "r");
if (!fp) {
nextemail = 1;
@ -397,14 +397,14 @@ void update_inbox(uint16_t nummsgs) {
}
for (msg = 1; msg <= nummsgs; ++msg) {
strcpy(linebuf, "");
sprintf(filename, "%s/EMAIL.%u", cfg_spooldir, msg);
sprintf(filename, "%s/SPOOL/EMAIL.%u", cfg_emaildir, msg);
fp = fopen(filename, "r");
if (!fp) {
printf("Can't open %s\n", filename);
error_exit();
}
hdrs.emailnum = nextemail;
sprintf(filename, "%s/EMAIL.%u", cfg_inboxdir, nextemail++);
sprintf(filename, "%s/INBOX/EMAIL.%u", cfg_emaildir, nextemail++);
puts(filename);
destfp = fopen(filename, "wb");
if (!destfp) {
@ -526,7 +526,7 @@ void main(void) {
printf(" %u message(s), %lu total bytes\n", nummsgs, bytes);
for (msg = 1; msg <= nummsgs; ++msg) {
sprintf(filename, "%s/EMAIL.%u", cfg_spooldir, msg);
sprintf(filename, "%s/SPOOL/EMAIL.%u", cfg_emaildir, msg);
remove(filename); /// TO MAKE DEBUGGING EASIER - GET RID OF THIS
fp = fopen(filename, "wb");
if (!fp) {