) {
int column = 0;
char ch = 0;
- if (!mptr) return;
+ char outbuf[1024];
+ int len = 0;
+ int nllen = 0;
+ if (!mptr) return;
+ nllen = strlen(nl);
while (ch=*(mptr++), ch > 0) {
if (ch == '\n') {
- cprintf("%s", nl);
+ client_write(outbuf, len);
+ len = 0;
+ client_write(nl, nllen);
column = 0;
}
else if (ch == '\r') {
}
else if (isspace(ch)) {
if (column > 72) { /* Beyond 72 columns, break on the next space */
- cprintf("%s", nl);
+ client_write(outbuf, len);
+ len = 0;
+ client_write(nl, nllen);
column = 0;
}
else {
- cprintf("%c", ch);
+ outbuf[len++] = ch;
+ ++column;
}
}
else {
+ outbuf[len++] = ch;
+ ++column;
if (column > 1000) { /* Beyond 1000 columns, break anywhere */
- cprintf("%s", nl);
+ client_write(outbuf, len);
+ len = 0;
+ client_write(nl, nllen);
column = 0;
}
- cprintf("%c", ch);
- ++column;
}
}
+ if (len) {
+ client_write(outbuf, len);
+ len = 0;
+ client_write(nl, nllen);
+ column = 0;
+ }
}
(void *)&ma, 0);
}
else if (mode == MT_RFC822) { /* unparsed RFC822 dump */
- char *start_of_text = NULL;
- start_of_text = strstr(mptr, "\n\r\n");
- if (start_of_text == NULL) start_of_text = strstr(mptr, "\n\n");
- if (start_of_text == NULL) start_of_text = mptr;
- ++start_of_text;
- start_of_text = strstr(start_of_text, "\n");
- ++start_of_text;
+ int eoh = 0;
char outbuf[1024];
int outlen = 0;
int nllen = strlen(nl);
prev_ch = 0;
- while (ch=*mptr, ch!=0) {
- if (ch==13) {
+ while (*mptr != '\0') {
+ if (*mptr == '\r') {
/* do nothing */
}
else {
+ if ((!eoh) &&
+ (*mptr == '\n'))
+ {
+ eoh = (*(mptr+1) == '\r') && (*(mptr+2) == '\n');
+ if (!eoh)
+ eoh = *(mptr+1) == '\n';
+ }
+
if (
- ((headers_only == HEADERS_NONE) && (mptr >= start_of_text))
- || ((headers_only == HEADERS_ONLY) && (mptr < start_of_text))
+ ((headers_only == HEADERS_NONE) && (eoh))
+ || ((headers_only == HEADERS_ONLY) && (!eoh))
|| ((headers_only != HEADERS_NONE) && (headers_only != HEADERS_ONLY))
) {
- if (ch == 10) {
- sprintf(&outbuf[outlen], "%s", nl);
+ if (*mptr == '\n') {
+ memcpy(&outbuf[outlen], nl, nllen);
outlen += nllen;
+ outbuf[outlen] = '\0';
}
else {
- outbuf[outlen++] = ch;
+ outbuf[outlen++] = *mptr;
}
}
}
if (flags & ESC_DOT)
{
- if ((prev_ch == 10) && (ch == '.') && ((*(mptr+1) == 13) || (*(mptr+1) == 10)))
+ if ((prev_ch == '\n') && (*mptr == '.') && ((*(mptr+1) == '\r') || (*(mptr+1) == '\n')))
{
outbuf[outlen++] = '.';
}
}
- prev_ch = ch;
+ prev_ch = *mptr;
++mptr;
if (outlen > 1000) {
client_write(outbuf, outlen);