1 /* mime.h
2  */
3 
4 struct hblk {
5     int	    tnum;
6     short   cnt;
7     char    indent;
8 };
9 
10 struct mime_sect {
11     MIME_SECT* prev;
12     char*   filename;
13     char*   type_name;
14     char*   type_params;
15     char*   boundary;
16     int     html_line_start;
17     HBLK*   html_blks;
18     short   type;
19     short   encoding;
20     short   part;
21     short   total;
22     short   boundary_len;
23     short   flags;
24     short   html;
25     short   html_blkcnt;
26 };
27 
28 #define MSF_INLINE	0x0001
29 #define MSF_ALTERNATIVE	0x0002
30 #define MSF_ALTERNADONE	0x0004
31 
32 /* Only used with HTMLTEXT_MIME */
33 #define HF_IN_TAG	0x0001
34 #define HF_IN_COMMENT	0x0002
35 #define HF_IN_HIDING	0x0004
36 #define HF_IN_PRE	0x0008
37 #define HF_IN_DQUOTE	0x0010
38 #define HF_IN_SQUOTE	0x0020
39 #define HF_QUEUED_P	0x0040
40 #define HF_P_OK		0x0080
41 #define HF_QUEUED_NL	0x0100
42 #define HF_NL_OK	0x0200
43 #define HF_NEED_INDENT	0x0400
44 #define HF_SPACE_OK	0x0800
45 #define HF_COMPACT	0x1000
46 
47 #define HTML_MAX_BLOCKS	256
48 
49 #define TF_BLOCK	0x0001		/* This implies TF_HAS_CLOSE */
50 #define TF_HAS_CLOSE	0x0002
51 #define TF_NL		0x0004
52 #define TF_P		0x0008
53 #define TF_BR		0x0010
54 #define TF_LIST		0x0020
55 #define TF_HIDE		0x0040
56 #define TF_SPACE	0x0080
57 #define TF_TAB		0x0100
58 
59 #define TAG_BLOCKQUOTE	0
60 #define TAG_BR		(TAG_BLOCKQUOTE+1)
61 #define TAG_DIV		(TAG_BR+1)
62 #define TAG_HR		(TAG_DIV+1)
63 #define TAG_IMG		(TAG_HR+1)
64 #define TAG_LI		(TAG_IMG+1)
65 #define TAG_OL		(TAG_LI+1)
66 #define TAG_P		(TAG_OL+1)
67 #define TAG_PRE		(TAG_P+1)
68 #define TAG_SCRIPT	(TAG_PRE+1)
69 #define TAG_STYLE	(TAG_SCRIPT+1)
70 #define TAG_TD		(TAG_STYLE+1)
71 #define TAG_TH		(TAG_TD+1)
72 #define TAG_TR		(TAG_TH+1)
73 #define TAG_TITLE	(TAG_TR+1)
74 #define TAG_UL		(TAG_TITLE+1)
75 #define LAST_TAG	(TAG_UL+1)
76 
77 #define CLOSING_TAG	0
78 #define OPENING_TAG	1
79 
80 struct html_tags {
81     char* name;
82     char length;
83     int flags;
84 };
85 
86 #ifndef DOINIT
87 EXT HTML_TAGS tagattr[LAST_TAG];
88 #else
89 
90 HTML_TAGS tagattr[LAST_TAG] = {
91  /* name               length   flags */
92     {"blockquote",	10,	TF_BLOCK | TF_P | TF_NL			},
93     {"br",		 2,	TF_NL | TF_BR				},
94     {"div",		 3,	TF_BLOCK | TF_NL			},
95     {"hr",		 2,	TF_NL					},
96     {"img",		 3,	0					},
97     {"li",		 2,	TF_NL					},
98     {"ol",		 2,	TF_BLOCK | TF_P | TF_NL | TF_LIST	},
99     {"p",		 1,	TF_HAS_CLOSE | TF_P | TF_NL		},
100     {"pre",		 3,	TF_BLOCK | TF_P | TF_NL			},
101     {"script",		 6,	TF_BLOCK | TF_HIDE			},
102     {"style",		 5,	TF_BLOCK | TF_HIDE			},
103     {"td",		 2,	TF_TAB					},
104     {"th",		 2,	TF_TAB					},
105     {"tr",		 2,	TF_NL					},
106     {"title",		 5,	TF_BLOCK | TF_HIDE			},
107     {"ul",		 2,	TF_BLOCK | TF_P | TF_NL | TF_LIST	},
108 };
109 #endif
110 
111 EXT LIST* mimecap_list;
112 
113 #define mimecap_ptr(n) ((MIMECAP_ENTRY*)listnum2listitem(mimecap_list,(long)(n)))
114 
115 EXT MIME_SECT mime_article;
116 EXT MIME_SECT* mime_section INIT(&mime_article);
117 EXT short mime_state;
118 EXT char* multipart_separator INIT("-=-=-=-=-=-");
119 
120 #define NOT_MIME	0
121 #define TEXT_MIME	1
122 #define ISOTEXT_MIME	2
123 #define MESSAGE_MIME	3
124 #define MULTIPART_MIME	4
125 #define IMAGE_MIME	5
126 #define AUDIO_MIME	6
127 #define APP_MIME	7
128 #define UNHANDLED_MIME	8
129 #define SKIP_MIME	9
130 #define DECODE_MIME	10
131 #define BETWEEN_MIME	11
132 #define END_OF_MIME	12
133 #define HTMLTEXT_MIME	13
134 #define ALTERNATE_MIME	14
135 
136 #define MENCODE_NONE		0
137 #define MENCODE_BASE64		1
138 #define MENCODE_QPRINT		2
139 #define MENCODE_UUE		3
140 #define MENCODE_UNHANDLED	4
141 
142 struct mimecap_entry {
143     char* contenttype;
144     char* command;
145     char* testcommand;
146     char* label;
147     int flags;
148 };
149 
150 #define MCF_NEEDSTERMINAL	0x0001
151 #define MCF_COPIOUSOUTPUT	0x0002
152 
153 EXT bool auto_view_inline INIT(FALSE);
154 EXT char* mime_getc_line INIT(NULL);
155 
156 /* DON'T EDIT BELOW THIS LINE OR YOUR CHANGES WILL BE LOST! */
157 
158 void mime_init _((void));
159 void mime_ReadMimecap _((char*));
160 MIMECAP_ENTRY* mime_FindMimecapEntry _((char*,int));
161 bool mime_TypesMatch _((char*,char*));
162 int mime_Exec _((char*));
163 void mime_InitSections _((void));
164 void mime_PushSection _((void));
165 bool mime_PopSection _((void));
166 void mime_ClearStruct _((MIME_SECT*));
167 void mime_SetArticle _((void));
168 void mime_ParseType _((MIME_SECT*,char*));
169 void mime_ParseDisposition _((MIME_SECT*,char*));
170 void mime_ParseEncoding _((MIME_SECT*,char*));
171 void mime_ParseSubheader _((FILE*,char*));
172 void mime_SetState _((char*));
173 int mime_EndOfSection _((char*));
174 char* mime_ParseParams _((char*));
175 char* mime_FindParam _((char*,char*));
176 char* mime_SkipWhitespace _((char*));
177 void mime_DecodeArticle _((bool_int));
178 void mime_Description _((MIME_SECT*,char*,int));
179 int qp_decodestring _((char*,char*,bool_int));
180 int qp_decode _((FILE*,int));
181 int b64_decodestring _((char*,char*));
182 int b64_decode _((FILE*,int));
183 int cat_decode _((FILE*,int));
184 int filter_html _((char*,char*));
185