]> diplodocus.org Git - nmh/blobdiff - sbr/m_getfld.c
Updates for 1.7 release.
[nmh] / sbr / m_getfld.c
index ef36a6e52cf36206a44a008526470980c70fcdd0..d74f3869a3fc2f079d218e69a08a0c83bbc45450 100644 (file)
@@ -205,6 +205,14 @@ static int m_Eom (m_getfld_state_t);
 #define eom(c,s)       (s->msg_style != MS_DEFAULT && \
                         ((c) == *s->msg_delim && m_Eom(s)))
 
 #define eom(c,s)       (s->msg_style != MS_DEFAULT && \
                         ((c) == *s->msg_delim && m_Eom(s)))
 
+/*
+ * Maildrop styles
+ */
+#define        MS_DEFAULT      0       /* default (one msg per file) */
+#define        MS_UNKNOWN      1       /* type not known yet         */
+#define        MS_MBOX         2       /* Unix-style "from" lines    */
+#define        MS_MMDF         3       /* string MMDF_DELIM          */
+
 /* This replaces the old approach, with its direct access to stdio
  * internals.  It uses one fread() to load a buffer that we manage.
  *
 /* This replaces the old approach, with its direct access to stdio
  * internals.  It uses one fread() to load a buffer that we manage.
  *
@@ -806,7 +814,7 @@ m_unknown(m_getfld_state_t *gstate, FILE *iob)
        /* not a Unix style maildrop */
        s->readpos -= s->bytes_read;
        s->bytes_read = 0;
        /* not a Unix style maildrop */
        s->readpos -= s->bytes_read;
        s->bytes_read = 0;
-       delimstr = mmdlm1;
+       delimstr = MMDF_DELIM;
        s->msg_style = MS_MMDF;
     }
 
        s->msg_style = MS_MMDF;
     }
 
@@ -874,6 +882,7 @@ m_Eom (m_getfld_state_t s)
     int i;
     char text[MAX_DELIMITER_SIZE];
     char *cp;
     int i;
     char text[MAX_DELIMITER_SIZE];
     char *cp;
+    int adjust = 1;
 
     for (i = 0, cp = text; i < s->edelimlen; ++i, ++cp) {
        int c2;
 
     for (i = 0, cp = text; i < s->edelimlen; ++i, ++cp) {
        int c2;
@@ -882,22 +891,31 @@ m_Eom (m_getfld_state_t s)
            *cp = '\0';
            break;
        }
            *cp = '\0';
            break;
        }
-        *cp = c2;
+       *cp = c2;
     }
 
     if (i != s->edelimlen  ||
         strncmp (text, (char *)s->edelim, s->edelimlen)) {
     }
 
     if (i != s->edelimlen  ||
         strncmp (text, (char *)s->edelim, s->edelimlen)) {
-       if (i == 0 && s->msg_style == MS_MBOX)
+       if (i == 0 && s->msg_style == MS_MBOX) {
            /* the final newline in the (brain damaged) unix-format
             * maildrop is part of the delimiter - delete it.
             */
            return 1;
            /* the final newline in the (brain damaged) unix-format
             * maildrop is part of the delimiter - delete it.
             */
            return 1;
+       }
+
+       if (i <= 2  &&  s->msg_style == MS_MBOX  &&
+           i != s->edelimlen  &&  ! strncmp(text, s->fdelim, i)) {
+           /* If all or part of fdelim appeared at the end of the file,
+              back up even more so that the bytes are included in the
+              message. */
+           adjust = 2;
+       }
 
        /* Did not find delimiter, so restore the read position.
           Note that on input, a character had already been read
           with Getc().  It will be unget by m_getfld () on return. */
 
        /* Did not find delimiter, so restore the read position.
           Note that on input, a character had already been read
           with Getc().  It will be unget by m_getfld () on return. */
-       s->readpos -= s->bytes_read - 1;
-       s->bytes_read = 1;
+       s->readpos -= s->bytes_read - adjust;
+       s->bytes_read = adjust;
        return 0;
     }
 
        return 0;
     }