4 * @ALLOW_GENFLAGS: -T0 -T1 -F0 -F1 -G0 -G1 -G2 -P
8 * Parses unix mail boxes into headers and bodies.
16 # Buffer the header names.
17 action bufHeadName { fsm->headName.append(fc); }
19 # Buffer the header content.
20 action bufHeadContent { fsm->headContent.append(fc); }
22 # Terminate a header. If it is an interesting header then prints it.
23 action finBufHeadContent {
24 /* Terminate the buffers. */
25 fsm->headName.append(0);
26 fsm->headContent.append(0);
28 /* Print the header. Interesting headers. */
29 printf("%s:%s\n", fsm->headName.data, fsm->headContent.data);
31 /* Clear for the next time we use them. */
32 fsm->headName.empty();
33 fsm->headContent.empty();
37 printf("NEW MESSAGE\n");
40 # Prints a blank line after the end of the headers of each message.
45 # Helpers we will use in matching the date section of the from line.
46 day = /[A-Z][a-z][a-z]/;
47 month = /[A-Z][a-z][a-z]/;
48 year = /[0-9][0-9][0-9][0-9]/;
49 time = /[0-9][0-9]:[0-9][0-9]/ . ( /:[0-9][0-9]/ | '' );
50 letterZone = /[A-Z][A-Z][A-Z]/;
51 numZone = /[+\-][0-9][0-9][0-9][0-9]/;
52 zone = letterZone | numZone;
53 dayNum = /[0-9 ][0-9]/;
55 # These are the different formats of the date minus an obscure
56 # type that has a funny string 'remote from xxx' on the end. Taken
57 # from c-client in the imap-2000 distribution.
58 date = day . ' ' . month . ' ' . dayNum . ' ' . time . ' ' .
59 ( year | year . ' ' . zone | zone . ' ' . year );
61 # Note the priority assignment on the end of the from line. While we
62 # matching the body of a message we may enter into this machine. We will
63 # not leave the body of the previous message until this entire from line is
65 fromLine = 'From ' . /[^\n]/* . ' ' . date . '\n' @(new_msg,1) @msgstart;
67 # The types of characters that can be used as a header name.
71 # The name of the header.
72 hchar+ $bufHeadName . ':'
73 # The content of the header. Look out for continuations.
74 . ( (extend - '\n') $bufHeadContent | '\n'. [ \t] @bufHeadContent )*
75 # Buffer must end with a newline that does not continue.
76 . '\n' %finBufHeadContent;
78 messageLine = ( extend - '\n' )* . '\n' @(new_msg, 0);
80 # When we get to the last newline we are still matching messageLine
81 # so on the last newline it will think we are still in the message.
82 # We need this because we can't assume that every newline means
83 # the end of the current message, whereas at the same time we requre
84 # that there be a newline before the fromLine of the next message.
85 message = ( fromLine . header* . '\n' @blankLine . messageLine* . '\n' );
87 # Its important that the priority in the fromLine gets bumped up
88 # so that we are able to move to new messages. Otherwise we
89 # will always stay in the message body of the first message.
101 void MBox::execute( char *data, int len )
105 char *pe = data + len;
114 if ( cs == MBox_error )
116 if ( cs >= MBox_first_final )
123 void test( char *buf )
125 int len = strlen( buf );
127 mbox.execute( buf, len );
128 if ( mbox.finish() > 0 )
138 "From email address goes here Wed Nov 28 13:30:05 2001 -0500\n"
139 "Header1: this is the header contents\n"
140 " there is more on the second line\n"
141 " and more on the third line.\n"
144 "This is the message data\n"
146 "From email Wed Nov 28 13:30:05 2001 -0500\n"
154 "From user@host.dom Wed Nov 28 13:30:05 2001\n"
156 "There are no headers. \n"
158 "From email Wed Nov 28 13:30:05 EST 2000\n"
160 "There are no headers.\n"
165 "From user@host.dom Wed Nov 28 13:30:05 2001\n"
171 "There are no headers. \n"
176 "From user@host.dom Wed Nov 28 13:30:05 2001\n"
182 "There are no headers. \n"
184 ">From user@host.dom Wed Nov 28 13:30:05 2001\n"
189 "From user@host.dom Wed Nov 28 13:30:05 2001\n"
195 "There are no headers. \n"
197 "From user@host.dom Wed Nov 28 13:30:05 2001\n"
202 "From user@host.dom Wed Nov 28 13:30:05 2001\n"
208 "There are no headers. \n"
210 "From user@host.dom Wed Nov 28 13:30:05 2001\n"
218 #ifdef _____OUTPUT_____
220 Header1: this is the header contents there is more on the second line and more on the third line.