]>
diplodocus.org Git - nmh/blob - sbr/m_getfld.c
6691e6095a4679f7ec429182ae279ebb739bae28
2 * m_getfld.c -- read/parse a message
4 * This code is Copyright (c) 2002, by the authors of nmh. See the
5 * COPYRIGHT file in the root directory of the nmh distribution for
6 * complete copyright information.
16 Reads an Internet message (RFC 5322), or one or more messages
17 stored in a maildrop in mbox (RFC 4155) or MMDF format, from a file
18 stream. Each call to m_getfld() reads one header field, or a
19 portion of the body, in sequence.
23 gstate: opaque parse state
24 bufsz: maximum number of characters to load into buf
25 iob: input file stream
29 name: header field name (array of size NAMESZ=999)
30 buf: either a header field body or message body
31 bufsz: number of characters loaded into buf
32 (return value): message parse state on return from function
36 void m_getfld_state_destroy (m_getfld_state_t *gstate): destroys
37 the parse state pointed to by the gstate argument.
39 m_getfld_state_reset (m_getfld_state_t *gstate): resets the parse
42 void m_unknown(FILE *iob): Determines the message delimiter string
43 for the maildrop. Called by inc and scan when reading from a
48 m_getfld() retains state internally between calls in the
49 m_getfld_state_t variable. These are used for detecting the end of
50 each message when reading maildrops:
63 m_getfld_state_t gstate = 0;
65 int state = m_getfld (&gstate, ...);
67 m_getfld_state_destroy (&gstate);
69 The state is retained internally by gstate. To reset its state to FLD:
70 m_getfld_state_reset (&gstate);
73 /* The following described the old implementation. The high-level
74 structure hasn't changed, but some of the details have. I'm
75 leaving this as-is, though, for posterity.
78 /* This module has a long and checkered history. First, it didn't burst
79 maildrops correctly because it considered two CTRL-A:s in a row to be
80 an inter-message delimiter. It really is four CTRL-A:s followed by a
81 newline. Unfortunately, MMDF will convert this delimiter *inside* a
82 message to a CTRL-B followed by three CTRL-A:s and a newline. This
83 caused the old version of m_getfld() to declare eom prematurely. The
84 fix was a lot slower than
86 c == '\001' && peekc (iob) == '\001'
88 but it worked, and to increase generality, MBOX style maildrops could
89 be parsed as well. Unfortunately the speed issue finally caught up with
90 us since this routine is at the very heart of MH.
92 To speed things up considerably, the routine Eom() was made an auxiliary
93 function called by the macro eom(). Unless we are bursting a maildrop,
94 the eom() macro returns FALSE saying we aren't at the end of the
97 The next thing to do is to read the mts.conf file and initialize
98 delimiter[] and delimlen accordingly...
100 After mhl was made a built-in in msh, m_getfld() worked just fine
101 (using m_unknown() at startup). Until one day: a message which was
102 the result of a bursting was shown. Then, since the burst boundaries
103 aren't CTRL-A:s, m_getfld() would blinding plunge on past the boundary.
104 Very sad. The solution: introduce m_eomsbr(). This hook gets called
105 after the end of each line (since testing for eom involves an fseek()).
106 This worked fine, until one day: a message with no body portion arrived.
109 while (eom (c = Getc (iob), iob))
112 loop caused m_getfld() to return FMTERR. So, that logic was changed to
113 check for (*eom_action) and act accordingly.
115 This worked fine, until one day: someone didn't use four CTRL:A's as
116 their delimiters. So, the bullet got bit and we read mts.h and
117 continue to struggle on. It's not that bad though, since the only time
118 the code gets executed is when inc (or msh) calls it, and both of these
119 have already called mts_init().
121 ------------------------
122 (Written by Van Jacobson for the mh6 m_getfld, January, 1986):
124 This routine was accounting for 60% of the cpu time used by most mh
125 programs. I spent a bit of time tuning and it now accounts for <10%
126 of the time used. Like any heavily tuned routine, it's a bit
127 complex and you want to be sure you understand everything that it's
128 doing before you start hacking on it. Let me try to emphasize
129 that: every line in this atrocity depends on every other line,
130 sometimes in subtle ways. You should understand it all, in detail,
131 before trying to change any part. If you do change it, test the
132 result thoroughly (I use a hand-constructed test file that exercises
133 all the ways a header name, header body, header continuation,
134 header-body separator, body line and body eom can align themselves
135 with respect to a buffer boundary). "Minor" bugs in this routine
136 result in garbaged or lost mail.
138 If you hack on this and slow it down, I, my children and my
139 children's children will curse you.
141 This routine gets used on three different types of files: normal,
142 single msg files, "packed" unix or mmdf mailboxs (when used by inc)
143 and packed, directoried bulletin board files (when used by msh).
144 The biggest impact of different file types is in "eom" testing. The
145 code has been carefully organized to test for eom at appropriate
146 times and at no other times (since the check is quite expensive).
147 I have tried to arrange things so that the eom check need only be
148 done on entry to this routine. Since an eom can only occur after a
149 newline, this is easy to manage for header fields. For the msg
150 body, we try to efficiently search the input buffer to see if
151 contains the eom delimiter. If it does, we take up to the
152 delimiter, otherwise we take everything in the buffer. (The change
153 to the body eom/copy processing produced the most noticeable
154 performance difference, particularly for "inc" and "show".)
156 There are three qualitatively different things this routine busts
157 out of a message: field names, field text and msg bodies. Field
158 names are typically short (~8 char) and the loop that extracts them
159 might terminate on a colon, newline or max width. I considered
160 using a Vax "scanc" to locate the end of the field followed by a
161 "memmove" but the routine call overhead on a Vax is too large for this
162 to work on short names. If Berkeley ever makes "inline" part of the
163 C optimiser (so things like "scanc" turn into inline instructions) a
164 change here would be worthwhile.
166 Field text is typically 60 - 100 characters so there's (barely)
167 a win in doing a routine call to something that does a "locc"
168 followed by a "bmove". About 30% of the fields have continuations
169 (usually the 822 "received:" lines) and each continuation generates
170 another routine call. "Inline" would be a big win here, as well.
172 Messages, as of this writing, seem to come in two flavors: small
173 (~1K) and long (>2K). Most messages have 400 - 600 bytes of headers
174 so message bodies average at least a few hundred characters.
175 Assuming your system uses reasonably sized stdio buffers (1K or
176 more), this routine should be able to remove the body in large
177 (>500 byte) chunks. The makes the cost of a call to "memmove"
178 small but there is a premium on checking for the eom in packed
179 maildrops. The eom pattern is always a simple string so we can
180 construct an efficient pattern matcher for it (e.g., a Vax "matchc"
181 instruction). Some thought went into recognizing the start of
182 an eom that has been split across two buffers.
184 This routine wants to deal with large chunks of data so, rather
185 than "getc" into a local buffer, it uses stdio's buffer. If
186 you try to use it on a non-buffered file, you'll get what you
187 deserve. This routine "knows" that struct FILEs have a _ptr
188 and a _cnt to describe the current state of the buffer and
189 it knows that _filbuf ignores the _ptr & _cnt and simply fills
190 the buffer. If stdio on your system doesn't work this way, you
191 may have to make small changes in this routine.
193 This routine also "knows" that an EOF indication on a stream is
194 "sticky" (i.e., you will keep getting EOF until you reposition the
195 stream). If your system doesn't work this way it is broken and you
196 should complain to the vendor. As a consequence of the sticky
197 EOF, this routine will never return any kind of EOF status when
198 there is data in "name" or "buf").
204 struct m_getfld_state
;
205 static int m_Eom (m_getfld_state_t
);
207 #define eom(c,s) (s->msg_style != MS_DEFAULT && \
208 ((c) == *s->msg_delim && m_Eom(s)))
210 /* This replaces the old approach, with its direct access to stdio
211 * internals. It uses one fread() to load a buffer that we manage.
213 * MSG_INPUT_SIZE is the size of the buffer.
214 * MAX_DELIMITER_SIZE is the maximum size of the delimiter used to
215 * separate messages in a maildrop, such as mbox "From ".
217 * Some of the tests in the test suite assume a MSG_INPUT_SIZE
220 #define MSG_INPUT_SIZE NMH_BUFSIZ
221 #define MAX_DELIMITER_SIZE 5
223 struct m_getfld_state
{
224 char msg_buf
[2 * MSG_INPUT_SIZE
+ MAX_DELIMITER_SIZE
];
226 char *end
; /* One past the last character read in. */
227 /* The following support tracking of the read position in the
228 input file stream so that callers can interleave m_getfld()
229 calls with ftell() and fseek(). bytes_read replaces the old
230 m_getfld() msg_count global. last_caller_pos is stored when
231 leaving m_getfld()/m_unknown(), then checked on the next entry.
232 last_internal_pos is used to remember the position used
233 internally by m_getfld() (read_more(), actually). */
235 off_t total_bytes_read
; /* by caller, not necessarily from input file */
236 off_t last_caller_pos
;
237 off_t last_internal_pos
;
243 * The "full" delimiter string for a packed maildrop consists
244 * of a newline followed by the actual delimiter. E.g., the
245 * full string for a Unix maildrop would be: "\n\nFrom ".
246 * "fdelim" points to the start of the full string and is used
247 * in the BODY case of the main routine to search the buffer for
248 * a possible eom. Msg_delim points to the first character of
249 * the actual delim. string (i.e., fdelim+1). edelim
250 * points to the 2nd character of actual delimiter string. It
251 * is used in m_Eom because the first character of the string
252 * has been read and matched before m_Eom is called.
266 m_getfld_state_init (m_getfld_state_t
*gstate
, FILE *iob
) {
271 s
->readpos
= s
->end
= s
->msg_buf
;
272 s
->bytes_read
= s
->total_bytes_read
= 0;
273 s
->last_caller_pos
= s
->last_internal_pos
= 0;
276 s
->msg_style
= MS_DEFAULT
;
278 s
->fdelim
= s
->delimend
= s
->edelim
= NULL
;
279 s
->fdelimlen
= s
->edelimlen
= 0;
281 s
->track_filepos
= 0;
284 /* scan() needs to force a state an initial state of FLD for each message. */
286 m_getfld_state_reset (m_getfld_state_t
*gstate
) {
288 (*gstate
)->state
= FLD
;
292 /* If the caller interleaves ftell*()/fseek*() calls with m_getfld()
293 calls, m_getfld() must keep track of the file position. The caller
294 must use this function to inform m_getfld(). */
296 m_getfld_track_filepos (m_getfld_state_t
*gstate
, FILE *iob
) {
298 m_getfld_state_init (gstate
, iob
);
301 (*gstate
)->track_filepos
= 1;
304 void m_getfld_state_destroy (m_getfld_state_t
*gstate
) {
305 m_getfld_state_t s
= *gstate
;
318 Summary of file and message input buffer positions:
320 input file -------------------------------------------EOF
322 last_caller_pos last_internal_pos
325 msg_buf --------------------EOF
329 |<>|=retained characters, difference
330 between last_internal_pos and
331 first readpos value after reading
332 in new chunk in read_more()
334 When returning from m_getfld()/m_unknown():
335 1) Save the internal file position in last_internal_pos. That's the
336 m_getfld() position reference in the input file.
337 2) Set file stream position so that callers can use ftell().
339 When entering m_getfld()/m_unknown():
340 Check to see if the call had changed the file position. If so,
341 adjust the internal position reference accordingly. If not, restore
342 the internal file position from last_internal_pos.
347 enter_getfld (m_getfld_state_t
*gstate
, FILE *iob
) {
353 m_getfld_state_init (gstate
, iob
);
358 /* This is ugly and no longer necessary, but is retained just in
359 case it's needed again. The parser used to open the input file
360 multiple times, so we had to always use the FILE * that's
361 passed to m_getfld(). Now the parser inits a new
362 m_getfld_state for each file. See comment below about the
363 readpos shift code being currently unused. */
366 if (!s
->track_filepos
)
370 if (pos
== 0 && s
->last_internal_pos
== 0)
373 if (s
->last_internal_pos
== 0) {
374 s
->total_bytes_read
= pos
;
378 pos_movement
= pos
- s
->last_caller_pos
; /* Can be < 0. */
379 if (pos_movement
== 0) {
380 pos
= s
->last_internal_pos
;
382 /* The current file stream position differs from the
383 last one, so caller must have called ftell/o().
384 Or, this is the first call and the file position
387 if (s
->readpos
+ pos_movement
>= s
->msg_buf
&&
388 s
->readpos
+ pos_movement
< s
->end
) {
389 /* This is currently unused. It could be used by
390 parse_mime() if it was changed to use a global
392 /* We can shift readpos and remain within the
393 bounds of msg_buf. */
394 s
->readpos
+= pos_movement
;
395 s
->total_bytes_read
+= pos_movement
;
396 pos
= s
->last_internal_pos
;
400 /* This seek skips past an integral number of
401 chunks of size MSG_INPUT_SIZE. */
402 fseeko (iob
, pos
/MSG_INPUT_SIZE
* MSG_INPUT_SIZE
, SEEK_SET
);
403 num_read
= fread (s
->msg_buf
, 1, MSG_INPUT_SIZE
, iob
);
404 s
->readpos
= s
->msg_buf
+ pos
% MSG_INPUT_SIZE
;
405 s
->end
= s
->msg_buf
+ num_read
;
406 s
->total_bytes_read
= pos
;
410 fseeko (iob
, pos
, SEEK_SET
);
414 leave_getfld (m_getfld_state_t s
) {
415 s
->total_bytes_read
+= s
->bytes_read
;
417 if (s
->track_filepos
) {
418 /* Save the internal file position that we use for the input buffer. */
419 s
->last_internal_pos
= ftello (s
->iob
);
421 /* Set file stream position so that callers can use ftell(). */
422 fseeko (s
->iob
, s
->total_bytes_read
, SEEK_SET
);
423 s
->last_caller_pos
= ftello (s
->iob
);
428 read_more (m_getfld_state_t s
) {
429 /* Retain at least edelimlen characters that have already been
430 read so that we can back up to them in m_Eom(). */
431 ssize_t retain
= s
->edelimlen
;
434 if (retain
< s
->end
- s
->readpos
)
435 retain
= s
->end
- s
->readpos
;
436 assert (retain
<= s
->readpos
- s
->msg_buf
);
438 /* Move what we want to retain at end of the buffer to the beginning. */
439 memmove (s
->msg_buf
, s
->readpos
- retain
, retain
);
441 s
->readpos
= s
->msg_buf
+ retain
;
442 num_read
= fread (s
->readpos
, 1, MSG_INPUT_SIZE
, s
->iob
);
443 s
->end
= s
->readpos
+ num_read
;
448 /* The return values of the following functions are a bit
449 subtle. They can return 0x00 - 0xff as a valid character,
450 but EOF is typically 0xffffffff. */
452 Getc (m_getfld_state_t s
) {
453 if ((s
->end
- s
->readpos
< 1 && read_more (s
) == 0) ||
454 s
->readpos
>= s
->end
)
458 return (unsigned char)*s
->readpos
++;
462 Peek (m_getfld_state_t s
) {
463 if (s
->end
- s
->readpos
< 1 && read_more (s
) == 0) {
466 return s
->readpos
< s
->end
? (unsigned char) *s
->readpos
: EOF
;
470 Ungetc (int c
, m_getfld_state_t s
) {
471 if (s
->readpos
== s
->msg_buf
) {
475 return *--s
->readpos
= (unsigned char) c
;
480 m_getfld (m_getfld_state_t
*gstate
, char name
[NAMESZ
], char *buf
, int *bufsz
,
487 enter_getfld (gstate
, iob
);
490 if ((c
= Getc(s
)) == EOF
) {
493 return s
->state
= FILEEOF
;
496 /* flush null messages */
497 while ((c
= Getc(s
)) != EOF
&& eom (c
, s
))
504 return s
->state
= FILEEOF
;
509 if (c
== '\n' || c
== '-') {
510 /* we hit the header/body separator */
511 while (c
!= '\n' && (c
= Getc(s
)) != EOF
)
514 if (c
== EOF
|| (c
= Getc(s
)) == EOF
|| eom (c
, s
)) {
515 /* flush null messages */
516 while ((c
= Getc(s
)) != EOF
&& eom (c
, s
))
522 return s
->state
= FILEEOF
;
528 * get the name of this component. take characters up
529 * to a ':', a newline or NAMESZ-1 characters, whichever
534 /* Get the field name. The first time through the loop,
535 this copies out the first character, which was loaded
536 into c prior to loop entry. Initialize n to 1 to
539 c
!= ':' && c
!= '\n' && c
!= EOF
&& n
< max
;
544 /* Check for next character, which is either the space after
545 the ':' or the first folded whitespace. */
548 if (c
== EOF
|| (next_char
= Peek (s
)) == EOF
) {
549 *bufsz
= *cp
= *buf
= 0;
550 inform("eof encountered in field \"%s\"", name
);
552 return s
->state
= FMTERR
;
556 /* If c isn't ':' here, something went wrong. Possibilities are:
557 * . hit a newline (error)
558 * . got more than namesz chars. (error)
561 /* Finished header name, fall through to FLDPLUS below. */
562 } else if (c
== '\n') {
563 /* We hit the end of the line without seeing ':' to
564 * terminate the field name. This is usually (always?)
565 * spam. But, blowing up is lame, especially when
566 * scan(1)ing a folder with such messages. Pretend such
567 * lines are the first of the body (at least mutt also
568 * handles it this way). */
570 /* See if buf can hold this line, since we were assuming
571 * we had a buffer of NAMESZ, not bufsz. */
572 /* + 1 for the newline */
573 if (*bufsz
< n
+ 1) {
574 /* No, it can't. Oh well, guess we'll blow up. */
575 *bufsz
= *cp
= *buf
= 0;
576 inform("eol encountered in field \"%s\"", name
);
580 memcpy (buf
, name
, n
- 1);
583 /* Indicate this wasn't a header field using a character
584 that can't appear in a header field. */
586 /* The last character read was '\n'. s->bytes_read
587 (and n) include that, but it was not put into the
588 name array in the for loop above. So subtract 1. */
589 *bufsz
= --s
->bytes_read
; /* == n - 1 */
591 return s
->state
= BODY
;
594 /* By design, the loop above discards the last character
595 it had read. It's in c, use it. */
597 *bufsz
= *cp
= *buf
= 0;
598 inform("field name \"%s\" exceeds %d bytes", name
,
604 /* Trim any trailing spaces from the end of name. */
605 while (isspace ((unsigned char) *--cp
) && cp
>= name
) continue;
607 /* readpos points to the first character of the field body. */
612 * get (more of) the text of a field. Take
613 * characters up to the end of this field (newline
614 * followed by non-blank) or bufsz-1 characters.
621 for (finished
= 0; ! finished
; ) {
622 while (c
!= '\n' && c
!= EOF
&& n
++ < max
) {
623 if ((c
= Getc (s
)) != EOF
)
630 /* The dest buffer is full. Need to back the read
631 pointer up by one because when m_getfld() is
632 reentered, it will read a character. Then
633 we'll jump right to the FLDPLUS handling code,
634 which will not store that character, but
635 instead move on to the next one. */
636 if (s
->readpos
> s
->msg_buf
) {
642 } else if (c
!= ' ' && c
!= '\t') {
643 /* The next character is not folded whitespace, so
644 prepare to move on to the next field. It's OK
645 if c is EOF, it will be handled on the next
646 call to m_getfld (). */
650 /* Folded header field, continues on the next line. */
653 *bufsz
= s
->bytes_read
;
660 * get the message body up to bufsz characters or the
661 * end of the message.
667 /* Back up and store the current position. */
669 c
= s
->end
- s
->readpos
< max
? s
->end
- s
->readpos
: max
;
670 if (s
->msg_style
!= MS_DEFAULT
&& c
> 1) {
672 * packed maildrop - only take up to the (possible)
673 * start of the next message. This "matchc" should
674 * probably be a Boyer-Moore matcher for non-vaxen,
675 * particularly since we have the alignment table
676 * all built for the end-of-buffer test (next).
677 * But our vax timings indicate that the "matchc"
678 * instruction is 50% faster than a carefully coded
679 * B.M. matcher for most strings. (So much for elegant
680 * algorithms vs. brute force.) Since I (currently)
681 * run MH on a vax, we use the matchc instruction. --vj
685 if ((ep
= memmem(bp
, c
, s
->fdelim
, s
->fdelimlen
)))
689 * There's no delim in the buffer but there may be
690 * a partial one at the end. If so, we want to leave
691 * it so the "eom" check on the next call picks it up.
692 * Use a modified Boyer-Moore matcher to make this
693 * check relatively cheap. The first "if" figures
694 * out what position in the pattern matches the last
695 * character in the buffer. The inner "while" matches
696 * the pattern against the buffer, backwards starting
697 * at that position. Note that unless the buffer
698 * ends with one of the characters in the pattern
699 * (excluding the first and last), we do only one test.
704 if ((sp
= s
->pat_map
[(unsigned char) *ep
])) {
706 /* This if() is true unless (a) the buffer is too
707 * small to contain this delimiter prefix, or
708 * (b) it contains exactly enough chars for the
710 * For case (a) obviously we aren't going to match.
711 * For case (b), if the buffer really contained exactly
712 * a delim prefix, then the m_eom call at entry
713 * should have found it. Thus it's not a delim
714 * and we know we won't get a match.
716 if (((sp
- s
->fdelim
) + 2) <= c
) {
718 /* Unfortunately although fdelim has a preceding NUL
719 * we can't use this as a sentinel in case the buffer
720 * contains a NUL in exactly the wrong place (this
721 * would cause us to run off the front of fdelim).
723 while (*--ep
== *--cp
)
726 if (cp
< s
->fdelim
) {
727 /* we matched the entire delim prefix,
728 * so only take the buffer up to there.
729 * we know ep >= bp -- check above prevents underrun
735 /* try matching one less char of delim string */
737 } while (--sp
> s
->fdelim
);
741 memcpy( buf
, bp
, c
);
742 /* Advance the current position to reflect the copy out.
743 c is less than or equal to the number of bytes remaining
744 in the read buffer, so will not overrun it. */
747 /* Subtract 1 from c because the first character was read by
748 Getc(), and therefore already accounted for in s->bytes_read. */
749 s
->bytes_read
+= c
- 1;
750 *bufsz
= s
->bytes_read
;
755 adios (NULL
, "m_getfld() called with bogus state of %d", s
->state
);
766 m_unknown(m_getfld_state_t
*gstate
, FILE *iob
)
770 char text
[MAX_DELIMITER_SIZE
];
771 char from
[] = "From ";
776 enter_getfld (gstate
, iob
);
780 * Figure out what the message delimitter string is for this
781 * maildrop. (This used to be part of m_Eom but I didn't like
782 * the idea of an "if" statement that could only succeed on the
783 * first call to m_Eom getting executed on each call, i.e., at
784 * every newline in the message).
786 * If the first line of the maildrop is a Unix "From " line, we
787 * say the style is MBOX and eat the rest of the line. Otherwise
788 * we say the style is MMDF and look for the delimiter string
789 * specified when nmh was built (or from the mts.conf file).
792 s
->msg_style
= MS_UNKNOWN
;
794 for (i
= 0, cp
= text
; i
< sizeof text
; ++i
, ++cp
) {
795 if ((c
= Getc (s
)) == EOF
) {
803 if (i
== sizeof from
-1 && strncmp (text
, "From ", sizeof from
-1) == 0) {
804 s
->msg_style
= MS_MBOX
;
805 delimstr
= "\nFrom ";
806 while ((c
= Getc(s
)) != EOF
&& c
!= '\n')
809 /* not a Unix style maildrop */
810 s
->readpos
-= s
->bytes_read
;
813 s
->msg_style
= MS_MMDF
;
816 c
= strlen (delimstr
);
817 s
->fdelim
= mh_xmalloc (c
+ 3); /* \0, \n, delimstr, \0 */
820 s
->fdelimlen
= c
+ 1;
821 s
->msg_delim
= s
->fdelim
+1;
822 strcpy (s
->msg_delim
, delimstr
);
823 s
->edelim
= s
->msg_delim
+1;
824 s
->edelimlen
= c
- 1;
825 s
->delimend
= s
->msg_delim
+ s
->edelimlen
;
826 if (s
->edelimlen
<= 1)
827 adios (NULL
, "maildrop delimiter must be at least 2 bytes");
829 /* Now malloc'd memory at s->fdelim-1 referenced several times:
831 * delimstr "\nFrom " "\001\001\001\001\n"
833 * s->fdelim \0"\n\nFrom " \0"\n\001\001\001\001\n"
835 * s->msg_delim "\nFrom " "\001\001\001\001\n"
836 * s->edelim "From " "\001\001\001\n"
838 * s->delimend " " "\n"
842 * build a Boyer-Moore end-position map for the matcher in m_getfld.
843 * N.B. - we don't match just the first char (since it's the newline
844 * separator) or the last char (since the matchc would have found it
845 * if it was a real delim).
847 s
->pat_map
= (char **) mh_xcalloc (256, sizeof(char *));
849 for (cp
= s
->fdelim
+ 1; cp
< s
->delimend
; cp
++ )
850 s
->pat_map
[(unsigned char)*cp
] = cp
;
852 if (s
->msg_style
== MS_MMDF
) {
853 /* flush extra msg hdrs */
854 while ((c
= Getc(s
)) != EOF
&& eom (c
, s
))
865 * test for msg delimiter string
869 m_Eom (m_getfld_state_t s
)
872 char text
[MAX_DELIMITER_SIZE
];
875 for (i
= 0, cp
= text
; i
< s
->edelimlen
; ++i
, ++cp
) {
878 if ((c2
= Getc (s
)) == EOF
) {
886 if (i
!= s
->edelimlen
||
887 strncmp (text
, (char *)s
->edelim
, s
->edelimlen
)) {
888 if (i
== 0 && s
->msg_style
== MS_MBOX
)
889 /* the final newline in the (brain damaged) unix-format
890 * maildrop is part of the delimitter - delete it.
894 /* Did not find delimiter, so restore the read position.
895 Note that on input, a character had already been read
896 with Getc(). It will be unget by m_getfld () on return. */
897 s
->readpos
-= s
->bytes_read
- 1;
902 if (s
->msg_style
== MS_MBOX
) {
904 while ((c
= Getc(s
)) != EOF
&& c
!= '\n')