xref: /inferno-os/module/rfc822.m (revision 0e96539ff7cff23233d3f0a64bb285b385a3a1f4)
1RFC822: module
2{
3	PATH: con "/dis/lib/rfc822.dis";
4
5	init: fn(b: Bufio);
6
7	# TO DO: multipart ...
8
9	# token values reserved to represent a word and a quoted string
10	Word, QString: con 1+iota;
11
12	Maxrequest: con 16*1024;	# more than enough for anything sensible
13
14	Rfclex: adt {
15		fd:	ref Bufio->Iobuf;	# open on a single line
16		wordval:	string;		# text if Word or QString
17		tok:	int;				# last token seen
18		eof:	int;				# end of file (ignore subsequent ungetc)
19
20		seen:	list of (int, string);	# pushback
21
22		mk:		fn(a: array of byte): ref Rfclex;
23		getc:		fn(p: self ref Rfclex): int;
24		ungetc:	fn(p: self ref Rfclex);
25		lex:		fn(p: self ref Rfclex): int;
26		unlex:	fn(p: self ref Rfclex);
27		skipws:	fn(p: self ref Rfclex): int;
28
29		line:		fn(p: self ref Rfclex): string;
30	};
31
32	readheaders:	fn(fd: ref Bufio->Iobuf, limit: int): array of (string, array of byte);
33	parseparams:	fn(ps: ref Rfclex): list of (string, string);
34	parsecontent:	fn(ps: ref Rfclex, multipart: int, head: list of ref Content): list of ref Content;
35	mimefields:	fn(ps: ref Rfclex): list of (string, list of (string, string));
36	# TO DO: parse addresses
37
38	quotable:	fn(s: string): int;
39	quote:	fn(s: string): string;
40
41	# convert an epoch time into http-formatted text
42	sec2date: fn(secs: int): string;
43
44	# convert a date in http text format to seconds from epoch
45	date2sec: fn(s: string): int;
46
47	# current time
48	now:	fn(): int;
49
50	# current time as a string
51	time:	fn(): string;
52
53	#
54	# mime-related things
55	#
56	Content: adt{
57		generic: string;
58		specific: string;
59		params: list of (string, string);
60
61		mk:	fn(generic: string, specific: string, params: list of (string, string)): ref Content;
62		check: fn(c: self ref Content, oks: list of ref Content): int;
63		text:	fn(c: self ref Content): string;
64	};
65
66	suffixclass: fn(name: string): (ref Content, ref Content);
67	dataclass:	fn(a: array of byte): (ref Content, ref Content);
68};
69