From 9cee699f998ba13b567db33481d518deaaaa5959 Mon Sep 17 00:00:00 2001 From: Bobbi Webber-Manners Date: Wed, 24 Jun 2020 17:50:19 -0400 Subject: [PATCH] Further improvements to pop65.c and email.c user interface --- apps/email.c | 20 +++++++++++++++++++- apps/pop65.c | 23 ++++++++++++++++++----- 2 files changed, 37 insertions(+), 6 deletions(-) diff --git a/apps/email.c b/apps/email.c index 114c7ba..ebda7b1 100644 --- a/apps/email.c +++ b/apps/email.c @@ -8,6 +8,7 @@ #include #include #include +#include char filename[80]; FILE *fp; @@ -95,6 +96,17 @@ void read_email_db(void) { } } +/* + * Print a header field from char postion start to end, + * padding with spaces as needed + */ +void printfield(char *s, uint8_t start, uint8_t end) { + uint8_t i; + uint8_t l = strlen(s); + for (i = start; i < end; i++) + putchar(i < l ? s[i] : ' '); +} + /* * Show email summary */ @@ -102,7 +114,13 @@ void email_summary(void) { uint16_t i = 1; struct emailhdrs *h = headers; while (h) { - printf("**%d %s %s %s", i++, h->date, h->from, h->subject); + printf("%02d|", i++); + printfield(h->date, 0, 16); + putchar('|'); + printfield(h->from, 0, 20); + putchar('|'); + printfield(h->subject, 0, 39); + //putchar('\r'); h = h->next; } } diff --git a/apps/pop65.c b/apps/pop65.c index 1a297c5..3df7ba4 100644 --- a/apps/pop65.c +++ b/apps/pop65.c @@ -365,6 +365,19 @@ void update_email_db(struct emailhdrs *h) { fclose(fp); } +/* + * Copy one header from source->dest, removing '\r' from end + */ +void copyheader(char *dest, char *source, uint16_t len) { + uint16_t i; + memset(dest, ' ', len); + for (i = 0; i < len; ++i) { + if ((*source == '\0') || (*source == '\r')) + return; + *dest++ = *source++; + } +} + /* * Update INBOX * Copy messages from spool dir to inbox and find headers of interest @@ -395,23 +408,23 @@ void update_inbox(uint16_t nummsgs) { while (get_line(fp)) { if (headers) { if (!strncmp(linebuf, "Date: ", 6)) { - strncpy(hdrs.date, linebuf + 6, 79); + copyheader(hdrs.date, linebuf + 6, 79); hdrs.date[79] = '\0'; } if (!strncmp(linebuf, "From: ", 6)) { - strncpy(hdrs.from, linebuf + 6, 79); + copyheader(hdrs.from, linebuf + 6, 79); hdrs.from[79] = '\0'; } if (!strncmp(linebuf, "To: ", 4)) { - strncpy(hdrs.to, linebuf + 4, 79); + copyheader(hdrs.to, linebuf + 4, 79); hdrs.to[79] = '\0'; } if (!strncmp(linebuf, "Cc: ", 4)) { - strncpy(hdrs.cc, linebuf + 4, 79); + copyheader(hdrs.cc, linebuf + 4, 79); hdrs.cc[79] = '\0'; } if (!strncmp(linebuf, "Subject: ", 9)) { - strncpy(hdrs.subject, linebuf + 9, 79); + copyheader(hdrs.subject, linebuf + 9, 79); hdrs.subject[79] = '\0'; } if (linebuf[0] == '\r')