Browse Source

preserve stray CRs in copy_msg_convert()

strip only CRs followed by LFs. this has mostly theoretical value (but
will make a subsequent change simpler).
wip/maildir-path-under-inbox
Oswald Buddenhagen 3 years ago
parent
commit
ed92816fdb
  1. 38
      src/sync_msg_cvt.c
  2. 2
      src/tst_msg_cvt.c

38
src/sync_msg_cvt.c

@ -13,19 +13,19 @@ copy_msg_bytes( char **out_ptr, const char *in_buf, uint *in_idx, uint in_len, i
char *out = *out_ptr; char *out = *out_ptr;
uint idx = *in_idx; uint idx = *in_idx;
if (out_cr != in_cr) { if (out_cr != in_cr) {
char c;
if (out_cr) { if (out_cr) {
for (; idx < in_len; idx++) { for (char c, pc = 0; idx < in_len; idx++) {
if ((c = in_buf[idx]) != '\r') { if (((c = in_buf[idx]) == '\n') && (pc != '\r'))
if (c == '\n')
*out++ = '\r'; *out++ = '\r';
*out++ = c; *out++ = c;
} pc = c;
} }
} else { } else {
for (; idx < in_len; idx++) { for (char c, pc = 0; idx < in_len; idx++) {
if ((c = in_buf[idx]) != '\r') if (((c = in_buf[idx]) == '\n') && (pc == '\r'))
out--;
*out++ = c; *out++ = c;
pc = c;
} }
} }
} else { } else {
@ -49,12 +49,13 @@ copy_msg_convert( int in_cr, int out_cr, copy_vars_t *vars )
if (vars->srec) { if (vars->srec) {
nloop: ; nloop: ;
uint start = idx; uint start = idx;
uint line_crs = 0; uint line_cr = 0;
char pc = 0;
while (idx < in_len) { while (idx < in_len) {
char c = in_buf[idx++]; char c = in_buf[idx++];
if (c == '\r') { if (c == '\n') {
line_crs++; if (pc == '\r')
} else if (c == '\n') { line_cr = 1;
if (!ebreak && starts_with_upper( in_buf + start, (int)(in_len - start), "X-TUID: ", 8 )) { if (!ebreak && starts_with_upper( in_buf + start, (int)(in_len - start), "X-TUID: ", 8 )) {
extra = (sbreak = start) - (ebreak = idx); extra = (sbreak = start) - (ebreak = idx);
if (!vars->minimal) if (!vars->minimal)
@ -67,9 +68,9 @@ copy_msg_convert( int in_cr, int out_cr, copy_vars_t *vars )
break2++; break2++;
} }
lines++; lines++;
hdr_crs += line_crs; hdr_crs += line_cr;
} }
if (idx - line_crs - 1 == start) { if (idx - line_cr - 1 == start) {
if (!ebreak) if (!ebreak)
sbreak = ebreak = start; sbreak = ebreak = start;
if (vars->minimal) { if (vars->minimal) {
@ -83,6 +84,7 @@ copy_msg_convert( int in_cr, int out_cr, copy_vars_t *vars )
} }
goto nloop; goto nloop;
} }
pc = c;
} }
free( in_buf ); free( in_buf );
return "has incomplete header"; return "has incomplete header";
@ -91,12 +93,14 @@ copy_msg_convert( int in_cr, int out_cr, copy_vars_t *vars )
extra += 8 + TUIDL + app_cr + 1; extra += 8 + TUIDL + app_cr + 1;
} }
if (out_cr != in_cr) { if (out_cr != in_cr) {
for (; idx < in_len; idx++) { for (char pc = 0; idx < in_len; idx++) {
char c = in_buf[idx]; char c = in_buf[idx];
if (c == '\r') if (c == '\n') {
bdy_crs++;
else if (c == '\n')
lines++; lines++;
if (pc == '\r')
bdy_crs++;
}
pc = c;
} }
extra -= hdr_crs + bdy_crs; extra -= hdr_crs + bdy_crs;
if (out_cr) if (out_cr)

2
src/tst_msg_cvt.c

@ -130,7 +130,7 @@ mintests( const char *name, const char *in, const char *out, int flagged )
tests( name, in, out, ADD_TUID, MINIMAL, flagged ); tests( name, in, out, ADD_TUID, MINIMAL, flagged );
} }
#define FROM "From: devil\r\n" #define FROM "From: de\rvil\r\n"
#define TO "To: me\r\n" #define TO "To: me\r\n"
#define IN_TUID "X-TUID: garbage\r\n" #define IN_TUID "X-TUID: garbage\r\n"
#define OUT_TUID "X-TUID: " TUID "\r\n" #define OUT_TUID "X-TUID: " TUID "\r\n"

Loading…
Cancel
Save