Skip to content

Commit

Permalink
g3-smtp-proto: fix check of next line
Browse files Browse the repository at this point in the history
  • Loading branch information
zh-jq-b committed Jun 6, 2024
1 parent aba9bf6 commit d1e7292
Showing 1 changed file with 13 additions and 20 deletions.
33 changes: 13 additions & 20 deletions lib/g3-smtp-proto/src/io/text_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,24 +56,21 @@ impl EndChecker {
self.check_n = false;
if left[0] == b'\n' {
self.found = true;
return offset + 1;
}
} else if self.check_r_n {
self.check_r_n = false;
if left[0] == b'\r' {
self.check_n = true;
return offset + 1;
}
} else if self.check_empty {
self.check_empty = false;
if left[0] == b'.' {
self.check_r_n = true;
return offset + 1;
}
}

if left[0] == b'\n' {
// next read will be next line
self.check_empty = true;
}
return offset + 1;
}
2 => {
if self.check_n {
Expand All @@ -86,19 +83,15 @@ impl EndChecker {
self.check_r_n = false;
if left == b"\r\n" {
self.found = true;
return offset + 2;
}
} else if self.check_empty {
self.check_empty = false;
if left == b".\r" {
self.check_n = true;
return offset + 2;
}
}

if left == b"\r\n" {
// next read will be next line
self.check_empty = true;
}
return offset + 2;
}
_ => {
if self.check_n {
Expand All @@ -120,16 +113,16 @@ impl EndChecker {
return offset + 3;
}
}

if let Some(p) = memchr::memchr(b'\n', left) {
// skip to next line
offset += p + 1;
self.check_empty = true;
} else {
return offset + left.len();
}
}
}

if let Some(p) = memchr::memchr(b'\n', left) {
// skip to next line
offset += p + 1;
self.check_empty = true;
} else {
return offset + left.len();
}
}
}
}
Expand Down

0 comments on commit d1e7292

Please sign in to comment.