mirror of
https://github.com/bobbimanners/emailler.git
synced 2024-06-08 00:29:29 +00:00
ATTACHER/NNTP65/POP65/REBUILD/SMTP65: Improvements to robustness. Tested.
This commit is contained in:
parent
9433042f5b
commit
1389c4948c
|
@ -159,8 +159,9 @@ void readconfigfile(void) {
|
|||
* Expects Apple ][ style line endings (CR) and does no conversion
|
||||
* fp - file to read from
|
||||
* writep - Pointer to buffer into which line will be written
|
||||
* n - length of buffer. Longer lines will be truncated and terminated with CR.
|
||||
*/
|
||||
int16_t get_line(FILE *fp, char *writep) {
|
||||
int16_t get_line(FILE *fp, char *writep, uint16_t n) {
|
||||
static uint16_t rd = 0; // Read
|
||||
static uint16_t end = 0; // End of valid data in buf
|
||||
uint16_t i = 0;
|
||||
|
@ -171,6 +172,11 @@ int16_t get_line(FILE *fp, char *writep) {
|
|||
}
|
||||
if (end == 0)
|
||||
return -1; // EOF
|
||||
if (i == n - 1) {
|
||||
writep[i - 1] = '\r';
|
||||
writep[i] = '\0';
|
||||
return i;
|
||||
}
|
||||
writep[i++] = buf[rd++];
|
||||
if (writep[i - 1] == '\r') {
|
||||
writep[i] = '\0';
|
||||
|
@ -587,7 +593,7 @@ void attach(char *fname) {
|
|||
|
||||
printf(" Copying email content ... "); // Space is for spinner to eat
|
||||
size = 0;
|
||||
while ((chars = get_line(fp, linebuf)) != -1) {
|
||||
while ((chars = get_line(fp, linebuf, LINEBUFSZ)) != -1) {
|
||||
size += chars;
|
||||
if (linebuf[0] == '\r')
|
||||
break;
|
||||
|
@ -600,7 +606,7 @@ void attach(char *fname) {
|
|||
fprintf(destfp, "--a2forever\r");
|
||||
fprintf(destfp, "Content-Type: text/plain; charset=US-ASCII\r");
|
||||
fprintf(destfp, "Content-Transfer-Encoding: 7bit\r\r");
|
||||
while ((chars = get_line(fp, linebuf)) != -1) {
|
||||
while ((chars = get_line(fp, linebuf, LINEBUFSZ)) != -1) {
|
||||
size += chars;
|
||||
fputs(linebuf, destfp);
|
||||
spinner(size, 0);
|
||||
|
|
|
@ -60,6 +60,7 @@ void confirm_exit(void) {
|
|||
cgetc();
|
||||
if (exec_email_on_exit) {
|
||||
sprintf(filename, "%s/EMAIL.SYSTEM", cfg_instdir);
|
||||
printf("%s\n", filename);
|
||||
exec(filename, NULL);
|
||||
}
|
||||
exit(0);
|
||||
|
@ -179,7 +180,7 @@ bool w5100_tcp_send_recv(char* sendbuf, char* recvbuf, size_t length,
|
|||
|
||||
if (mode == DATA_MODE) {
|
||||
//
|
||||
// Handle email body
|
||||
// Handle article body
|
||||
//
|
||||
uint16_t rcv, written;
|
||||
uint16_t len = 0;
|
||||
|
@ -354,11 +355,12 @@ int16_t get_line(FILE *fp, char *writep, uint16_t n) {
|
|||
}
|
||||
if (end == 0)
|
||||
return -1; // EOF
|
||||
if (i == n - 2) {
|
||||
writep[i] = '\r';
|
||||
writep[i + 1] = '\0';
|
||||
}
|
||||
writep[i++] = buf[rd++];
|
||||
if (i == n - 1) {
|
||||
writep[i - 1] = '\r';
|
||||
writep[i] = '\0';
|
||||
return i;
|
||||
}
|
||||
// The following line is safe because of linebuf_pad[]
|
||||
if ((writep[i - 1] == '\n') && (writep[i - 2] == '\r')) {
|
||||
writep[i - 1] = '\0'; // Remove LF
|
||||
|
|
59
apps/pop65.c
59
apps/pop65.c
|
@ -48,6 +48,8 @@ uint16_t pop_port;
|
|||
* Keypress before quit
|
||||
*/
|
||||
void confirm_exit(void) {
|
||||
fclose(fp);
|
||||
w5100_disconnect();
|
||||
printf("\n[Press Any Key]");
|
||||
cgetc();
|
||||
if (exec_email_on_exit) {
|
||||
|
@ -237,12 +239,14 @@ bool w5100_tcp_send_recv(char* sendbuf, char* recvbuf, size_t length,
|
|||
}
|
||||
} else {
|
||||
//
|
||||
// Handle short single packet ASCII text responses
|
||||
// Handle short single line ASCII text responses
|
||||
// Must fit in recvbuf[]
|
||||
//
|
||||
uint16_t rcv;
|
||||
uint16_t len = 0;
|
||||
uint8_t cont = 1;
|
||||
|
||||
while (1) {
|
||||
while (cont) {
|
||||
if (input_check_for_abort_key()) {
|
||||
printf("User abort\n");
|
||||
w5100_disconnect();
|
||||
|
@ -250,26 +254,33 @@ bool w5100_tcp_send_recv(char* sendbuf, char* recvbuf, size_t length,
|
|||
}
|
||||
|
||||
rcv = w5100_receive_request();
|
||||
if (rcv)
|
||||
break;
|
||||
if (!w5100_connected()) {
|
||||
printf("Connection lost\n");
|
||||
return false;
|
||||
if (!rcv) {
|
||||
cont = w5100_connected();
|
||||
if (cont)
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (rcv > length - len)
|
||||
rcv = length - len;
|
||||
if (rcv > length - len)
|
||||
rcv = length - len;
|
||||
|
||||
{
|
||||
// One less to allow for faster pre-increment below
|
||||
char *dataptr = recvbuf + len - 1;
|
||||
uint16_t i;
|
||||
for (i = 0; i < rcv; ++i) {
|
||||
// The variable is necessary to have cc65 generate code
|
||||
// suitable to access the W5100 auto-increment register.
|
||||
char data = *w5100_data;
|
||||
*++dataptr = data;
|
||||
if (rcv == 0) {
|
||||
return true; // This can happen on the final QUIT
|
||||
// printf("Buffer overflow\n"); // Should never happen
|
||||
// error_exit();
|
||||
}
|
||||
|
||||
{
|
||||
// One less to allow for faster pre-increment below
|
||||
char *dataptr = recvbuf + len - 1;
|
||||
uint16_t i;
|
||||
for (i = 0; i < rcv; ++i) {
|
||||
// The variable is necessary to have cc65 generate code
|
||||
// suitable to access the W5100 auto-increment register.
|
||||
char data = *w5100_data;
|
||||
*++dataptr = data;
|
||||
if (!memcmp(dataptr - 1, "\r\n", 2))
|
||||
cont = 0;
|
||||
}
|
||||
}
|
||||
w5100_receive_commit(rcv);
|
||||
len += rcv;
|
||||
|
@ -323,8 +334,9 @@ void readconfigfile(void) {
|
|||
* Expects CRLF line endings (CRLF) and converts to Apple II (CR) convention
|
||||
* fp - file to read from
|
||||
* writep - Pointer to buffer into which line will be written
|
||||
* n - length of buffer. Longer lines will be truncated and terminated with CR.
|
||||
*/
|
||||
int16_t get_line(FILE *fp, char *writep) {
|
||||
int16_t get_line(FILE *fp, char *writep, uint16_t n) {
|
||||
static uint16_t rd = 0; // Read
|
||||
static uint16_t end = 0; // End of valid data in buf
|
||||
uint16_t i = 0;
|
||||
|
@ -335,6 +347,11 @@ int16_t get_line(FILE *fp, char *writep) {
|
|||
}
|
||||
if (end == 0)
|
||||
return -1; // EOF
|
||||
if (i == n - 1) {
|
||||
writep[i - 1] = '\r';
|
||||
writep[i] = '\0';
|
||||
return i;
|
||||
}
|
||||
writep[i++] = buf[rd++];
|
||||
// The following line is safe because of linebuf_pad[]
|
||||
if ((writep[i - 1] == '\n') && (writep[i - 2] == '\r')) {
|
||||
|
@ -434,7 +451,7 @@ void update_inbox(uint16_t nummsgs) {
|
|||
hdrs.skipbytes = 0; // Just in case it doesn't get set
|
||||
hdrs.status = 'N';
|
||||
hdrs.tag = ' ';
|
||||
while ((chars = get_line(fp, linebuf)) != -1) {
|
||||
while ((chars = get_line(fp, linebuf, LINEBUFSZ)) != -1) {
|
||||
if (headers) {
|
||||
headerchars += chars;
|
||||
if (!strncmp(linebuf, "Date: ", 6)) {
|
||||
|
|
|
@ -49,9 +49,9 @@ void error_exit() {
|
|||
* Expects Apple ][ style line endings (CR) and does no conversion
|
||||
* fp - file to read from
|
||||
* writep - Pointer to buffer into which line will be written
|
||||
* pos - position in file is updated via this pointer
|
||||
* n - length of buffer. Longer lines will be truncated and terminated with CR.
|
||||
*/
|
||||
int16_t get_line(FILE *fp, char *writep) {
|
||||
int16_t get_line(FILE *fp, char *writep, uint16_t n) {
|
||||
static uint16_t rd = 0; // Read
|
||||
static uint16_t end = 0; // End of valid data in buf
|
||||
uint16_t i = 0;
|
||||
|
@ -62,6 +62,11 @@ int16_t get_line(FILE *fp, char *writep) {
|
|||
}
|
||||
if (end == 0)
|
||||
return -1; // EOF
|
||||
if (i == n - 1) {
|
||||
writep[i - 1] = '\r';
|
||||
writep[i] = '\0';
|
||||
return i;
|
||||
}
|
||||
writep[i++] = buf[rd++];
|
||||
if (writep[i - 1] == '\r') {
|
||||
writep[i] = '\0';
|
||||
|
@ -188,7 +193,7 @@ void repair_mailbox(void) {
|
|||
hdrs.skipbytes = 0; // Just in case it doesn't get set
|
||||
hdrs.status = 'R';
|
||||
hdrs.tag = ' ';
|
||||
while ((chars = get_line(fp, linebuf)) != -1) {
|
||||
while ((chars = get_line(fp, linebuf, LINEBUFSZ)) != -1) {
|
||||
if (headers) {
|
||||
headerchars += chars;
|
||||
if (!strncmp(linebuf, "Date: ", 6)) {
|
||||
|
|
|
@ -111,8 +111,9 @@ void spinner(uint32_t sz, uint8_t final) {
|
|||
* fp - file to read from
|
||||
* reset - if 1 then just reset the buffer and return
|
||||
* writep - Pointer to buffer into which line will be written
|
||||
* n - length of buffer. Longer lines will be truncated and terminated with CR.
|
||||
*/
|
||||
int16_t get_line(FILE *fp, uint8_t reset, char *writep) {
|
||||
int16_t get_line(FILE *fp, uint8_t reset, char *writep, uint16_t n) {
|
||||
static uint16_t rd = 0; // Read
|
||||
static uint16_t end = 0; // End of valid data in buf
|
||||
uint16_t i = 0;
|
||||
|
@ -127,6 +128,11 @@ int16_t get_line(FILE *fp, uint8_t reset, char *writep) {
|
|||
}
|
||||
if (end == 0)
|
||||
return -1; // EOF
|
||||
if (i == n - 1) {
|
||||
writep[i - 1] = '\r';
|
||||
writep[i] = '\0';
|
||||
return i;
|
||||
}
|
||||
writep[i++] = buf[rd++];
|
||||
if (writep[i - 1] == '\r') {
|
||||
writep[i] = '\0';
|
||||
|
@ -162,11 +168,11 @@ bool w5100_tcp_send_recv(char* sendbuf, char* recvbuf, size_t length,
|
|||
int16_t len;
|
||||
|
||||
filesize = 0;
|
||||
len = get_line(fp, 1, linebuf); // Reset buffer
|
||||
len = get_line(fp, 1, linebuf, LINEBUFSZ); // Reset buffer
|
||||
|
||||
while (cont) {
|
||||
|
||||
len = get_line(fp, 0, linebuf);
|
||||
len = get_line(fp, 0, linebuf, LINEBUFSZ);
|
||||
pos = 0;
|
||||
|
||||
if (len == -1) {
|
||||
|
@ -444,8 +450,8 @@ void update_sent_mbox(char *name) {
|
|||
hdrs.skipbytes = 0; // Just in case it doesn't get set
|
||||
hdrs.status = 'N';
|
||||
hdrs.tag = ' ';
|
||||
get_line(fp, 1, linebuf); // Reset buffer
|
||||
while ((chars = get_line(fp, 0, linebuf)) != -1) {
|
||||
get_line(fp, 1, linebuf, LINEBUFSZ); // Reset buffer
|
||||
while ((chars = get_line(fp, 0, linebuf, LINEBUFSZ)) != -1) {
|
||||
if (headers) {
|
||||
headerchars += chars;
|
||||
if (!strncmp(linebuf, "Date: ", 6)) {
|
||||
|
@ -556,7 +562,7 @@ void main(int argc, char *argv[]) {
|
|||
strcpy(recipients, "");
|
||||
|
||||
while (1) {
|
||||
if ((get_line(fp, 0, linebuf) == -1) || (linecount == 20)) {
|
||||
if ((get_line(fp, 0, linebuf, LINEBUFSZ) == -1) || (linecount == 20)) {
|
||||
if (strlen(recipients) == 0) {
|
||||
printf("No recipients (To or Cc) in %s. Skipping msg.\n", d->d_name);
|
||||
goto skiptonext;
|
||||
|
|
Loading…
Reference in New Issue
Block a user