]>
diplodocus.org Git - nmh/blob - sbr/m_getfld.c
1 /* m_getfld.c -- read/parse a message
3 * This code is Copyright (c) 2002, by the authors of nmh. See the
4 * COPYRIGHT file in the root directory of the nmh distribution for
5 * complete copyright information.
15 Reads an Internet message (RFC 5322), or one or more messages
16 stored in a maildrop in mbox (RFC 4155) or MMDF format, from a file
17 stream. Each call to m_getfld() reads one header field, or a
18 portion of the body, in sequence.
22 gstate: opaque parse state
23 bufsz: maximum number of characters to load into buf
24 iob: input file stream
28 name: header field name (array of size NAMESZ=999)
29 buf: either a header field body or message body
30 bufsz: number of characters loaded into buf
31 (return value): message parse state on return from function
35 void m_getfld_state_destroy (m_getfld_state_t *gstate): destroys
36 the parse state pointed to by the gstate argument.
38 m_getfld_state_reset (m_getfld_state_t *gstate): resets the parse
41 void m_unknown(FILE *iob): Determines the message delimiter string
42 for the maildrop. Called by inc and scan when reading from a
47 m_getfld() retains state internally between calls in the
48 m_getfld_state_t variable. These are used for detecting the end of
49 each message when reading maildrops:
62 m_getfld_state_t gstate = 0;
64 int state = m_getfld (&gstate, ...);
66 m_getfld_state_destroy (&gstate);
68 The state is retained internally by gstate. To reset its state to FLD:
69 m_getfld_state_reset (&gstate);
72 /* The following described the old implementation. The high-level
73 structure hasn't changed, but some of the details have. I'm
74 leaving this as-is, though, for posterity.
77 /* This module has a long and checkered history. First, it didn't burst
78 maildrops correctly because it considered two CTRL-A:s in a row to be
79 an inter-message delimiter. It really is four CTRL-A:s followed by a
80 newline. Unfortunately, MMDF will convert this delimiter *inside* a
81 message to a CTRL-B followed by three CTRL-A:s and a newline. This
82 caused the old version of m_getfld() to declare eom prematurely. The
83 fix was a lot slower than
85 c == '\001' && peekc (iob) == '\001'
87 but it worked, and to increase generality, MBOX style maildrops could
88 be parsed as well. Unfortunately the speed issue finally caught up with
89 us since this routine is at the very heart of MH.
91 To speed things up considerably, the routine Eom() was made an auxiliary
92 function called by the macro eom(). Unless we are bursting a maildrop,
93 the eom() macro returns FALSE saying we aren't at the end of the
96 The next thing to do is to read the mts.conf file and initialize
97 delimiter[] and delimlen accordingly...
99 After mhl was made a built-in in msh, m_getfld() worked just fine
100 (using m_unknown() at startup). Until one day: a message which was
101 the result of a bursting was shown. Then, since the burst boundaries
102 aren't CTRL-A:s, m_getfld() would blinding plunge on past the boundary.
103 Very sad. The solution: introduce m_eomsbr(). This hook gets called
104 after the end of each line (since testing for eom involves an fseek()).
105 This worked fine, until one day: a message with no body portion arrived.
108 while (eom (c = Getc (iob), iob))
111 loop caused m_getfld() to return FMTERR. So, that logic was changed to
112 check for (*eom_action) and act accordingly.
114 This worked fine, until one day: someone didn't use four CTRL:A's as
115 their delimiters. So, the bullet got bit and we read mts.h and
116 continue to struggle on. It's not that bad though, since the only time
117 the code gets executed is when inc (or msh) calls it, and both of these
118 have already called mts_init().
120 ------------------------
121 (Written by Van Jacobson for the mh6 m_getfld, January, 1986):
123 This routine was accounting for 60% of the cpu time used by most mh
124 programs. I spent a bit of time tuning and it now accounts for <10%
125 of the time used. Like any heavily tuned routine, it's a bit
126 complex and you want to be sure you understand everything that it's
127 doing before you start hacking on it. Let me try to emphasize
128 that: every line in this atrocity depends on every other line,
129 sometimes in subtle ways. You should understand it all, in detail,
130 before trying to change any part. If you do change it, test the
131 result thoroughly (I use a hand-constructed test file that exercises
132 all the ways a header name, header body, header continuation,
133 header-body separator, body line and body eom can align themselves
134 with respect to a buffer boundary). "Minor" bugs in this routine
135 result in garbaged or lost mail.
137 If you hack on this and slow it down, I, my children and my
138 children's children will curse you.
140 This routine gets used on three different types of files: normal,
141 single msg files, "packed" unix or mmdf mailboxs (when used by inc)
142 and packed, directoried bulletin board files (when used by msh).
143 The biggest impact of different file types is in "eom" testing. The
144 code has been carefully organized to test for eom at appropriate
145 times and at no other times (since the check is quite expensive).
146 I have tried to arrange things so that the eom check need only be
147 done on entry to this routine. Since an eom can only occur after a
148 newline, this is easy to manage for header fields. For the msg
149 body, we try to efficiently search the input buffer to see if
150 contains the eom delimiter. If it does, we take up to the
151 delimiter, otherwise we take everything in the buffer. (The change
152 to the body eom/copy processing produced the most noticeable
153 performance difference, particularly for "inc" and "show".)
155 There are three qualitatively different things this routine busts
156 out of a message: field names, field text and msg bodies. Field
157 names are typically short (~8 char) and the loop that extracts them
158 might terminate on a colon, newline or max width. I considered
159 using a Vax "scanc" to locate the end of the field followed by a
160 "memmove" but the routine call overhead on a Vax is too large for this
161 to work on short names. If Berkeley ever makes "inline" part of the
162 C optimiser (so things like "scanc" turn into inline instructions) a
163 change here would be worthwhile.
165 Field text is typically 60 - 100 characters so there's (barely)
166 a win in doing a routine call to something that does a "locc"
167 followed by a "bmove". About 30% of the fields have continuations
168 (usually the 822 "received:" lines) and each continuation generates
169 another routine call. "Inline" would be a big win here, as well.
171 Messages, as of this writing, seem to come in two flavors: small
172 (~1K) and long (>2K). Most messages have 400 - 600 bytes of headers
173 so message bodies average at least a few hundred characters.
174 Assuming your system uses reasonably sized stdio buffers (1K or
175 more), this routine should be able to remove the body in large
176 (>500 byte) chunks. The makes the cost of a call to "memmove"
177 small but there is a premium on checking for the eom in packed
178 maildrops. The eom pattern is always a simple string so we can
179 construct an efficient pattern matcher for it (e.g., a Vax "matchc"
180 instruction). Some thought went into recognizing the start of
181 an eom that has been split across two buffers.
183 This routine wants to deal with large chunks of data so, rather
184 than "getc" into a local buffer, it uses stdio's buffer. If
185 you try to use it on a non-buffered file, you'll get what you
186 deserve. This routine "knows" that struct FILEs have a _ptr
187 and a _cnt to describe the current state of the buffer and
188 it knows that _filbuf ignores the _ptr & _cnt and simply fills
189 the buffer. If stdio on your system doesn't work this way, you
190 may have to make small changes in this routine.
192 This routine also "knows" that an EOF indication on a stream is
193 "sticky" (i.e., you will keep getting EOF until you reposition the
194 stream). If your system doesn't work this way it is broken and you
195 should complain to the vendor. As a consequence of the sticky
196 EOF, this routine will never return any kind of EOF status when
197 there is data in "name" or "buf").
203 struct m_getfld_state
;
204 static int m_Eom (m_getfld_state_t
);
206 #define eom(c,s) (s->msg_style != MS_DEFAULT && \
207 ((c) == *s->msg_delim && m_Eom(s)))
209 /* This replaces the old approach, with its direct access to stdio
210 * internals. It uses one fread() to load a buffer that we manage.
212 * MSG_INPUT_SIZE is the size of the buffer.
213 * MAX_DELIMITER_SIZE is the maximum size of the delimiter used to
214 * separate messages in a maildrop, such as mbox "From ".
216 * Some of the tests in the test suite assume a MSG_INPUT_SIZE
219 #define MSG_INPUT_SIZE NMH_BUFSIZ
220 #define MAX_DELIMITER_SIZE 5
222 struct m_getfld_state
{
223 char msg_buf
[2 * MSG_INPUT_SIZE
+ MAX_DELIMITER_SIZE
];
225 char *end
; /* One past the last character read in. */
226 /* The following support tracking of the read position in the
227 input file stream so that callers can interleave m_getfld()
228 calls with ftell() and fseek(). bytes_read replaces the old
229 m_getfld() msg_count global. last_caller_pos is stored when
230 leaving m_getfld()/m_unknown(), then checked on the next entry.
231 last_internal_pos is used to remember the position used
232 internally by m_getfld() (read_more(), actually). */
234 off_t total_bytes_read
; /* by caller, not necessarily from input file */
235 off_t last_caller_pos
;
236 off_t last_internal_pos
;
242 * The "full" delimiter string for a packed maildrop consists
243 * of a newline followed by the actual delimiter. E.g., the
244 * full string for a Unix maildrop would be: "\n\nFrom ".
245 * "fdelim" points to the start of the full string and is used
246 * in the BODY case of the main routine to search the buffer for
247 * a possible eom. Msg_delim points to the first character of
248 * the actual delim. string (i.e., fdelim+1). edelim
249 * points to the 2nd character of actual delimiter string. It
250 * is used in m_Eom because the first character of the string
251 * has been read and matched before m_Eom is called.
265 m_getfld_state_init (m_getfld_state_t
*gstate
, FILE *iob
) {
270 s
->readpos
= s
->end
= s
->msg_buf
;
271 s
->bytes_read
= s
->total_bytes_read
= 0;
272 s
->last_caller_pos
= s
->last_internal_pos
= 0;
275 s
->msg_style
= MS_DEFAULT
;
277 s
->fdelim
= s
->delimend
= s
->edelim
= NULL
;
278 s
->fdelimlen
= s
->edelimlen
= 0;
280 s
->track_filepos
= 0;
283 /* scan() needs to force a state an initial state of FLD for each message. */
285 m_getfld_state_reset (m_getfld_state_t
*gstate
) {
287 (*gstate
)->state
= FLD
;
291 /* If the caller interleaves ftell*()/fseek*() calls with m_getfld()
292 calls, m_getfld() must keep track of the file position. The caller
293 must use this function to inform m_getfld(). */
295 m_getfld_track_filepos (m_getfld_state_t
*gstate
, FILE *iob
) {
297 m_getfld_state_init (gstate
, iob
);
300 (*gstate
)->track_filepos
= 1;
303 void m_getfld_state_destroy (m_getfld_state_t
*gstate
) {
304 m_getfld_state_t s
= *gstate
;
317 Summary of file and message input buffer positions:
319 input file -------------------------------------------EOF
321 last_caller_pos last_internal_pos
324 msg_buf --------------------EOF
328 |<>|=retained characters, difference
329 between last_internal_pos and
330 first readpos value after reading
331 in new chunk in read_more()
333 When returning from m_getfld()/m_unknown():
334 1) Save the internal file position in last_internal_pos. That's the
335 m_getfld() position reference in the input file.
336 2) Set file stream position so that callers can use ftell().
338 When entering m_getfld()/m_unknown():
339 Check to see if the call had changed the file position. If so,
340 adjust the internal position reference accordingly. If not, restore
341 the internal file position from last_internal_pos.
346 enter_getfld (m_getfld_state_t
*gstate
, FILE *iob
) {
352 m_getfld_state_init (gstate
, iob
);
357 /* This is ugly and no longer necessary, but is retained just in
358 case it's needed again. The parser used to open the input file
359 multiple times, so we had to always use the FILE * that's
360 passed to m_getfld(). Now the parser inits a new
361 m_getfld_state for each file. See comment below about the
362 readpos shift code being currently unused. */
365 if (!s
->track_filepos
)
369 if (pos
== 0 && s
->last_internal_pos
== 0)
372 if (s
->last_internal_pos
== 0) {
373 s
->total_bytes_read
= pos
;
377 pos_movement
= pos
- s
->last_caller_pos
; /* Can be < 0. */
378 if (pos_movement
== 0) {
379 pos
= s
->last_internal_pos
;
381 /* The current file stream position differs from the
382 last one, so caller must have called ftell/o().
383 Or, this is the first call and the file position
386 if (s
->readpos
+ pos_movement
>= s
->msg_buf
&&
387 s
->readpos
+ pos_movement
< s
->end
) {
388 /* This is currently unused. It could be used by
389 parse_mime() if it was changed to use a global
391 /* We can shift readpos and remain within the
392 bounds of msg_buf. */
393 s
->readpos
+= pos_movement
;
394 s
->total_bytes_read
+= pos_movement
;
395 pos
= s
->last_internal_pos
;
399 /* This seek skips past an integral number of
400 chunks of size MSG_INPUT_SIZE. */
401 fseeko (iob
, pos
/MSG_INPUT_SIZE
* MSG_INPUT_SIZE
, SEEK_SET
);
402 num_read
= fread (s
->msg_buf
, 1, MSG_INPUT_SIZE
, iob
);
403 s
->readpos
= s
->msg_buf
+ pos
% MSG_INPUT_SIZE
;
404 s
->end
= s
->msg_buf
+ num_read
;
405 s
->total_bytes_read
= pos
;
409 fseeko (iob
, pos
, SEEK_SET
);
413 leave_getfld (m_getfld_state_t s
) {
414 s
->total_bytes_read
+= s
->bytes_read
;
416 if (s
->track_filepos
) {
417 /* Save the internal file position that we use for the input buffer. */
418 s
->last_internal_pos
= ftello (s
->iob
);
420 /* Set file stream position so that callers can use ftell(). */
421 fseeko (s
->iob
, s
->total_bytes_read
, SEEK_SET
);
422 s
->last_caller_pos
= ftello (s
->iob
);
427 read_more (m_getfld_state_t s
) {
428 /* Retain at least edelimlen characters that have already been
429 read so that we can back up to them in m_Eom(). */
430 ssize_t retain
= s
->edelimlen
;
433 if (retain
< s
->end
- s
->readpos
)
434 retain
= s
->end
- s
->readpos
;
435 assert (retain
<= s
->readpos
- s
->msg_buf
);
437 /* Move what we want to retain at end of the buffer to the beginning. */
438 memmove (s
->msg_buf
, s
->readpos
- retain
, retain
);
440 s
->readpos
= s
->msg_buf
+ retain
;
441 num_read
= fread (s
->readpos
, 1, MSG_INPUT_SIZE
, s
->iob
);
442 s
->end
= s
->readpos
+ num_read
;
447 /* The return values of the following functions are a bit
448 subtle. They can return 0x00 - 0xff as a valid character,
449 but EOF is typically 0xffffffff. */
451 Getc (m_getfld_state_t s
) {
452 if ((s
->end
- s
->readpos
< 1 && read_more (s
) == 0) ||
453 s
->readpos
>= s
->end
)
457 return (unsigned char)*s
->readpos
++;
461 Peek (m_getfld_state_t s
) {
462 if (s
->end
- s
->readpos
< 1 && read_more (s
) == 0) {
465 return s
->readpos
< s
->end
? (unsigned char) *s
->readpos
: EOF
;
469 Ungetc (int c
, m_getfld_state_t s
) {
470 if (s
->readpos
== s
->msg_buf
) {
474 return *--s
->readpos
= (unsigned char) c
;
479 m_getfld (m_getfld_state_t
*gstate
, char name
[NAMESZ
], char *buf
, int *bufsz
,
486 enter_getfld (gstate
, iob
);
489 if ((c
= Getc(s
)) == EOF
) {
492 return s
->state
= FILEEOF
;
495 /* flush null messages */
496 while ((c
= Getc(s
)) != EOF
&& eom (c
, s
))
503 return s
->state
= FILEEOF
;
508 if (c
== '\n' || c
== '-') {
509 /* we hit the header/body separator */
510 while (c
!= '\n' && (c
= Getc(s
)) != EOF
)
513 if (c
== EOF
|| (c
= Getc(s
)) == EOF
|| eom (c
, s
)) {
514 /* flush null messages */
515 while ((c
= Getc(s
)) != EOF
&& eom (c
, s
))
521 return s
->state
= FILEEOF
;
527 * get the name of this component. take characters up
528 * to a ':', a newline or NAMESZ-1 characters, whichever
533 /* Get the field name. The first time through the loop,
534 this copies out the first character, which was loaded
535 into c prior to loop entry. Initialize n to 1 to
538 c
!= ':' && c
!= '\n' && c
!= EOF
&& n
< max
;
543 /* Check for next character, which is either the space after
544 the ':' or the first folded whitespace. */
547 if (c
== EOF
|| (next_char
= Peek (s
)) == EOF
) {
548 *bufsz
= *cp
= *buf
= 0;
549 inform("eof encountered in field \"%s\"", name
);
551 return s
->state
= FMTERR
;
555 /* If c isn't ':' here, something went wrong. Possibilities are:
556 * . hit a newline (error)
557 * . got more than namesz chars. (error)
560 /* Finished header name, fall through to FLDPLUS below. */
561 } else if (c
== '\n') {
562 /* We hit the end of the line without seeing ':' to
563 * terminate the field name. This is usually (always?)
564 * spam. But, blowing up is lame, especially when
565 * scan(1)ing a folder with such messages. Pretend such
566 * lines are the first of the body (at least mutt also
567 * handles it this way). */
569 /* See if buf can hold this line, since we were assuming
570 * we had a buffer of NAMESZ, not bufsz. */
571 /* + 1 for the newline */
572 if (*bufsz
< n
+ 1) {
573 /* No, it can't. Oh well, guess we'll blow up. */
574 *bufsz
= *cp
= *buf
= 0;
575 inform("eol encountered in field \"%s\"", name
);
579 memcpy (buf
, name
, n
- 1);
582 /* Indicate this wasn't a header field using a character
583 that can't appear in a header field. */
585 /* The last character read was '\n'. s->bytes_read
586 (and n) include that, but it was not put into the
587 name array in the for loop above. So subtract 1. */
588 *bufsz
= --s
->bytes_read
; /* == n - 1 */
590 return s
->state
= BODY
;
593 /* By design, the loop above discards the last character
594 it had read. It's in c, use it. */
596 *bufsz
= *cp
= *buf
= 0;
597 inform("field name \"%s\" exceeds %d bytes", name
,
603 /* Trim any trailing spaces from the end of name. */
604 while (isspace ((unsigned char) *--cp
) && cp
>= name
) continue;
606 /* readpos points to the first character of the field body. */
611 * get (more of) the text of a field. Take
612 * characters up to the end of this field (newline
613 * followed by non-blank) or bufsz-1 characters.
620 for (finished
= 0; ! finished
; ) {
621 while (c
!= '\n' && c
!= EOF
&& n
++ < max
) {
622 if ((c
= Getc (s
)) != EOF
)
629 /* The dest buffer is full. Need to back the read
630 pointer up by one because when m_getfld() is
631 reentered, it will read a character. Then
632 we'll jump right to the FLDPLUS handling code,
633 which will not store that character, but
634 instead move on to the next one. */
635 if (s
->readpos
> s
->msg_buf
) {
641 } else if (c
!= ' ' && c
!= '\t') {
642 /* The next character is not folded whitespace, so
643 prepare to move on to the next field. It's OK
644 if c is EOF, it will be handled on the next
645 call to m_getfld (). */
649 /* Folded header field, continues on the next line. */
652 *bufsz
= s
->bytes_read
;
659 * get the message body up to bufsz characters or the
660 * end of the message.
666 /* Back up and store the current position. */
668 c
= s
->end
- s
->readpos
< max
? s
->end
- s
->readpos
: max
;
669 if (s
->msg_style
!= MS_DEFAULT
&& c
> 1) {
671 * packed maildrop - only take up to the (possible)
672 * start of the next message. This "matchc" should
673 * probably be a Boyer-Moore matcher for non-vaxen,
674 * particularly since we have the alignment table
675 * all built for the end-of-buffer test (next).
676 * But our vax timings indicate that the "matchc"
677 * instruction is 50% faster than a carefully coded
678 * B.M. matcher for most strings. (So much for elegant
679 * algorithms vs. brute force.) Since I (currently)
680 * run MH on a vax, we use the matchc instruction. --vj
684 if ((ep
= memmem(bp
, c
, s
->fdelim
, s
->fdelimlen
)))
688 * There's no delim in the buffer but there may be
689 * a partial one at the end. If so, we want to leave
690 * it so the "eom" check on the next call picks it up.
691 * Use a modified Boyer-Moore matcher to make this
692 * check relatively cheap. The first "if" figures
693 * out what position in the pattern matches the last
694 * character in the buffer. The inner "while" matches
695 * the pattern against the buffer, backwards starting
696 * at that position. Note that unless the buffer
697 * ends with one of the characters in the pattern
698 * (excluding the first and last), we do only one test.
703 if ((sp
= s
->pat_map
[(unsigned char) *ep
])) {
705 /* This if() is true unless (a) the buffer is too
706 * small to contain this delimiter prefix, or
707 * (b) it contains exactly enough chars for the
709 * For case (a) obviously we aren't going to match.
710 * For case (b), if the buffer really contained exactly
711 * a delim prefix, then the m_eom call at entry
712 * should have found it. Thus it's not a delim
713 * and we know we won't get a match.
715 if (((sp
- s
->fdelim
) + 2) <= c
) {
717 /* Unfortunately although fdelim has a preceding NUL
718 * we can't use this as a sentinel in case the buffer
719 * contains a NUL in exactly the wrong place (this
720 * would cause us to run off the front of fdelim).
722 while (*--ep
== *--cp
)
725 if (cp
< s
->fdelim
) {
726 /* we matched the entire delim prefix,
727 * so only take the buffer up to there.
728 * we know ep >= bp -- check above prevents underrun
734 /* try matching one less char of delim string */
736 } while (--sp
> s
->fdelim
);
740 memcpy( buf
, bp
, c
);
741 /* Advance the current position to reflect the copy out.
742 c is less than or equal to the number of bytes remaining
743 in the read buffer, so will not overrun it. */
746 /* Subtract 1 from c because the first character was read by
747 Getc(), and therefore already accounted for in s->bytes_read. */
748 s
->bytes_read
+= c
- 1;
749 *bufsz
= s
->bytes_read
;
754 adios (NULL
, "m_getfld() called with bogus state of %d", s
->state
);
765 m_unknown(m_getfld_state_t
*gstate
, FILE *iob
)
769 char text
[MAX_DELIMITER_SIZE
];
770 char from
[] = "From ";
775 enter_getfld (gstate
, iob
);
779 * Figure out what the message delimitter string is for this
780 * maildrop. (This used to be part of m_Eom but I didn't like
781 * the idea of an "if" statement that could only succeed on the
782 * first call to m_Eom getting executed on each call, i.e., at
783 * every newline in the message).
785 * If the first line of the maildrop is a Unix "From " line, we
786 * say the style is MBOX and eat the rest of the line. Otherwise
787 * we say the style is MMDF and look for the delimiter string
788 * specified when nmh was built (or from the mts.conf file).
791 s
->msg_style
= MS_UNKNOWN
;
793 for (i
= 0, cp
= text
; i
< sizeof text
; ++i
, ++cp
) {
794 if ((c
= Getc (s
)) == EOF
) {
802 if (i
== sizeof from
-1 && strncmp (text
, "From ", sizeof from
-1) == 0) {
803 s
->msg_style
= MS_MBOX
;
804 delimstr
= "\nFrom ";
805 while ((c
= Getc(s
)) != EOF
&& c
!= '\n')
808 /* not a Unix style maildrop */
809 s
->readpos
-= s
->bytes_read
;
812 s
->msg_style
= MS_MMDF
;
815 c
= strlen (delimstr
);
816 s
->fdelim
= mh_xmalloc (c
+ 3); /* \0, \n, delimstr, \0 */
819 s
->fdelimlen
= c
+ 1;
820 s
->msg_delim
= s
->fdelim
+1;
821 strcpy (s
->msg_delim
, delimstr
);
822 s
->edelim
= s
->msg_delim
+1;
823 s
->edelimlen
= c
- 1;
824 s
->delimend
= s
->msg_delim
+ s
->edelimlen
;
825 if (s
->edelimlen
<= 1)
826 adios (NULL
, "maildrop delimiter must be at least 2 bytes");
828 /* Now malloc'd memory at s->fdelim-1 referenced several times:
830 * delimstr "\nFrom " "\001\001\001\001\n"
832 * s->fdelim \0"\n\nFrom " \0"\n\001\001\001\001\n"
834 * s->msg_delim "\nFrom " "\001\001\001\001\n"
835 * s->edelim "From " "\001\001\001\n"
837 * s->delimend " " "\n"
841 * build a Boyer-Moore end-position map for the matcher in m_getfld.
842 * N.B. - we don't match just the first char (since it's the newline
843 * separator) or the last char (since the matchc would have found it
844 * if it was a real delim).
846 s
->pat_map
= (char **) mh_xcalloc (256, sizeof(char *));
848 for (cp
= s
->fdelim
+ 1; cp
< s
->delimend
; cp
++ )
849 s
->pat_map
[(unsigned char)*cp
] = cp
;
851 if (s
->msg_style
== MS_MMDF
) {
852 /* flush extra msg hdrs */
853 while ((c
= Getc(s
)) != EOF
&& eom (c
, s
))
864 * test for msg delimiter string
868 m_Eom (m_getfld_state_t s
)
871 char text
[MAX_DELIMITER_SIZE
];
874 for (i
= 0, cp
= text
; i
< s
->edelimlen
; ++i
, ++cp
) {
877 if ((c2
= Getc (s
)) == EOF
) {
885 if (i
!= s
->edelimlen
||
886 strncmp (text
, (char *)s
->edelim
, s
->edelimlen
)) {
887 if (i
== 0 && s
->msg_style
== MS_MBOX
)
888 /* the final newline in the (brain damaged) unix-format
889 * maildrop is part of the delimitter - delete it.
893 /* Did not find delimiter, so restore the read position.
894 Note that on input, a character had already been read
895 with Getc(). It will be unget by m_getfld () on return. */
896 s
->readpos
-= s
->bytes_read
- 1;
901 if (s
->msg_style
== MS_MBOX
) {
903 while ((c
= Getc(s
)) != EOF
&& c
!= '\n')