-/* Find the last message in the file.
- * upon success return 0. If no message found - return -1 */
-
-int fseek_last_message (FILE * f)
-{
- long int pos;
- char buffer[BUFSIZ + 9]; /* 7 for "\n\nFrom " */
- int bytes_read;
- int i; /* Index into `buffer' for scanning. */
-
- memset (buffer, 0, sizeof(buffer));
- fseek (f, 0, SEEK_END);
- pos = ftell (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 * mutt_strlen(CRLF) */
- fseek (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 (!mutt_strncmp (buffer + i, "\n\nFrom ", mutt_strlen ("\n\nFrom ")))
- { /* found it - go to the beginning of the From */
- fseek (f, pos + i + 2, SEEK_SET);
- return 0;
- }
- bytes_read = BUFSIZ;
- }