istream-raw-mbox.c revision 183bea41fa640dc8117f3eb45ff935cd81377a84
const unsigned char *
buf, *p;
/* from_offset points to "\nFrom ", so unless we're at the beginning of the file, skip the initial \n */ /* From_-line is too long, but we should be able to parse what we have so far. */ /* EOF shouldn't happen */ /* broken From - should happen only at beginning of file if this isn't a mbox.. */ /* skip over From-line */ /* line was too long. skip the input until we find LF. */ /* EOF shouldn't happen */ /* Header didn't have ending \n */ /* "headers\n\nFrom ..", the second \n belongs to next message which we didn't know at the time yet. */ /* The +2 check is for CR+LF linefeeds */ const unsigned char *
buf;
/* fake our read count. needed because if in the end we have only one character in buffer and we skip it (as potential CR), we want to get back to this i_stream_raw_mbox_read() to read more data. */ /* From_-line is longer than our input buffer. finish the check without seeing the LF. */ /* we've read everything our parent stream /* parent stream is full, but we haven't returned all its bytes to our caller yet. */ /* we've read the whole file, final byte should be /* haven't seen From-line yet, so this mbox /* beginning of message, we haven't yet read our From-line */ /* we're at the end of file with CR+LF linefeeds? need more data to verify it. */ i_error(
"Next message unexpectedly corrupted in mbox file " /* got it. we don't want to return it however, so start again from headers */ /* See if we have From-line here - note that it works right only because all characters are different in mbox_from. */ ((i > 0 &&
buf[i-
1] ==
'\n') ||
(i >
1 &&
buf[i-
1] ==
'\r' &&
buf[i-
2] ==
'\n') ||
/* potential From-line, see if we have the rest of the line buffered. */ if (i >=
7 &&
buf[i-
7] ==
'\r') {
/* CR also belongs to it. */ /* even if we don't have the finish this check now. */ /* we have the whole From-line here now. See if it's a valid one. */ /* we want to go at least one byte further next time */ /* we're waiting for the \n at the end of From-line */ /* leave out the beginnings of potential From-line + CR */ /* istream_raw_mbox_set_next_offset() used invalid i_error(
"Next message unexpectedly lost from mbox file " static const struct stat *
const unsigned char *
data;
/* minimal: "From x Thu Nov 29 22:33:52 2001" = 31 chars */ i_error(
"Unexpectedly lost From-line from mbox file %s at " i_error(
"Unexpectedly lost From-line from mbox file " const unsigned char *
data;
/* if we already have the existing body size, use it as long as it's >= expected body_size. otherwise the previous parsing may have stopped at a From_-line that belongs to the body. */ /* If header_missing_eoh is set, the message body begins with a From_-line and the body_offset is pointing to the line *before* the first line of the body, i.e. the empty line separating the headers from the body. If that is the case, we'll have to skip over the empty line to get the correct /* invalid expected_body_size */ /* have to read through the message body */ /* if seeked is FALSE, we unlocked in the middle. don't try to use any cached state then. */ /* back to beginning of current message */