-static int fseeko_last_message (FILE * f)
-{
- LOFF_T pos;
- char buffer[BUFSIZ + 9]; /* 7 for "\n\nFrom " */
- int bytes_read;
- int i; /* Index into `buffer' for scanning. */
-
- memset (buffer, 0, sizeof (buffer));
- fseeko (f, 0, SEEK_END);
- pos = ftello (f);
-
- /* Set `bytes_read' to the size of the last, probably partial, buffer; 0 <
- * `bytes_read' <= `BUFSIZ'. */
- bytes_read = pos % BUFSIZ;
- if (bytes_read == 0)
- bytes_read = BUFSIZ;
- /* Make `pos' a multiple of `BUFSIZ' (0 if the file is short), so that all
- * reads will be on block boundaries, which might increase efficiency. */
- while ((pos -= bytes_read) >= 0) {
- /* we save in the buffer at the end the first 7 chars from the last read */
- strncpy (buffer + BUFSIZ, buffer, 5 + 2); /* 2 == 2 * m_strlen(CRLF) */
- fseeko (f, pos, SEEK_SET);
- bytes_read = fread (buffer, sizeof (char), bytes_read, f);
- if (bytes_read == -1)
- return -1;
- for (i = bytes_read; --i >= 0;)
- if (!str_ncmp (buffer + i, "\n\nFrom ", m_strlen("\n\nFrom "))) { /* found it - go to the beginning of the From */
- fseeko (f, pos + i + 2, SEEK_SET);
- return 0;
- }
- bytes_read = BUFSIZ;
- }
-
- /* here we are at the beginning of the file */
- if (!str_ncmp ("From ", buffer, 5)) {
- fseeko (f, 0, 0);
- return (0);
- }
-
- return (-1);
-}
-
-/* Return 1 if the last message is new */
-static int test_last_status_new (FILE * f)
-{
- HEADER *hdr;
- ENVELOPE *tmp_envelope;
- int result = 0;
-
- if (fseeko_last_message (f) == -1)
- return (0);
-
- hdr = mutt_new_header ();
- tmp_envelope = mutt_read_rfc822_header (f, hdr, 0, 0);
- if (!(hdr->read || hdr->old))
- result = 1;
-
- mutt_free_envelope (&tmp_envelope);
- mutt_free_header (&hdr);