1 /*
2 **
3 ** Copyright (C) 1993 Swedish University Network (SUNET)
4 **
5 **
6 ** This program is developed by UDAC, Uppsala University by commission
7 ** of the Swedish University Network (SUNET).
8 **
9 ** This program is free software; you can redistribute it and/or modify
10 ** it under the terms of the GNU General Public License as published by
11 ** the Free Software Foundation; either version 2 of the License, or
12 ** (at your option) any later version.
13 **
14 ** This program is distributed in the hope that it will be useful,
15 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ** MERCHANTABILITY or FITTNESS FOR A PARTICULAR PURPOSE. See the
17 ** GNU General Public License for more details.
18 **
19 ** You should have received a copy of the GNU General Public License
20 ** along with this program; if not, write to the Free Software
21 ** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 **
23 **
24 ** Martin.Wendel@its.uu.se
25 ** Torbjorn.Wictorin@its.uu.se
26 **
27 ** ITS
28 ** P.O. Box 887
29 ** S-751 08 Uppsala
30 ** Sweden
31 **
32 */
33 #include "emil.h"
34
encode_mailtool(struct message * m)35 void encode_mailtool(struct message *m)
36 {
37 char buf[HDRLEN];
38 if (m->sd->format == MAILTOOL &&
39 m->sd == m->td)
40 return;
41 if (m->level == 0)
42 {
43 rm_header(m, "X-Charset");
44 rm_header(m, "X-Char-Esc");
45 if (match(m->sd->type, "TEXT"))
46 {
47 add_header(m, "Content-Type", "text", MAILTOOL);
48 sprintf(buf, "%d", get_body_lines(m->td));
49 add_header(m, "X-lines", buf, MAILTOOL);
50 }
51 else
52 {
53 add_header(m, "Content-Type", "X-Sun-Attachment", MAILTOOL);
54 m->td->startbound = NEWSTR("----------");
55 }
56 }
57 else
58 {
59 unsigned char *dt = NULL;
60 if (m->td->encoding == EMULTI)
61 {
62 m->td->startbound = NEWSTR("----------");
63 return;
64 }
65 if ((dt = (char *)confextr("MAILTOOL", NULL, m->sd->type)) != NULL ||
66 (dt = (char *)confextr("MAILTOOL", NULL, "DEFAULT")) != NULL)
67 {
68 add_header(m, "X-Sun-Data-Type", dt, MAILTOOL);
69 }
70 else
71 {
72 add_header(m, "X-Sun-Data-Type", "default", MAILTOOL);
73 }
74
75
76 /*
77 if (match(m->sd->type, "TEXT"))
78 {
79 add_header(m, "X-Sun-Data-Type", "text", MAILTOOL);
80 }
81 else
82 if (match(m->sd->type, "APPLICATION"))
83 {
84 add_header(m, "X-Sun-Data-Type", "default-app", MAILTOOL);
85 }
86 else
87 if (match(m->sd->type, "GIF"))
88 {
89 add_header(m, "X-Sun-Data-Type", "gif-file", MAILTOOL);
90 }
91 else
92 if (match(m->sd->type, "ULAW"))
93 {
94 add_header(m, "X-Sun-Data-Type", "audio-file", MAILTOOL);
95 }
96 else
97 {
98 add_header(m, "X-Sun-Data-Type", "default", MAILTOOL);
99 }
100 */
101 switch (m->td->encoding) {
102 case EUUENCODE:
103 add_header(m, "X-Sun-Encoding-Info", "uuencode", MAILTOOL);
104 break;
105 case EBINHEX:
106 add_header(m, "X-Sun-Encoding-Info", "binhex", MAILTOOL);
107 break;
108 case EBASE64:
109 add_header(m, "X-Sun-Encoding-Info", "base64", MAILTOOL);
110 break;
111 }
112 if (m->sd->description != NULL)
113 add_header(m, "X-Sun-Data-description", m->sd->description, MAILTOOL);
114 else
115 add_header(m, "X-Sun-Data-description", "default", MAILTOOL);
116
117 if (m->sd->name != NULL)
118 add_header(m, "X-Sun-Data-name", m->sd->name, MAILTOOL);
119
120 sprintf(buf, "%d", get_body_lines(m->td));
121 add_header(m, "X-Sun-Content-lines", buf, MAILTOOL);
122 }
123 }
124
decode_mailtool(struct message * m)125 int decode_mailtool(struct message *m)
126 {
127 if (m->level == 0)
128 {
129 if (matchheader(m, "Content-Type", "text", MAILTOOL))
130 {
131 if ((m->sd->charset = (char *)gethval(m, "X-Sun-charset", MAILTOOL)) == NULL)
132 return(NOK);
133 m->sd->format = MAILTOOL;
134 m->sd->type = NEWSTR("TEXT");
135 m->sd->encoding = E7BIT;
136 }
137 else
138 /* Look for SUN Mailtool */
139 if (matchheader(m, "Content-Type", "X-Sun-Attachment", MAILTOOL))
140 {
141 m->sd->format = MAILTOOL;
142 m->sd->type = NEWSTR("MULTIPART");
143 m->sd->check = EMULTI;
144 m->sd->encoding = EMULTI;
145 m->sd->startbound = NEWSTR("----------");
146 }
147
148 if (m->sd->format == MAILTOOL)
149 {
150 m->sd->length = string2dec(gethval(m, "Content-length", MAILTOOL));
151 m->sd->bodylines = string2dec(gethval(m, "X-lines", MAILTOOL));
152 return(OK);
153 }
154 else
155 return(NOK);
156 }
157 /**
158 ** This is valid for SUN Mailtool message, except for root header
159 **/
160
161 if (m->sd->format == MAILTOOL && m->level != 0)
162 {
163 char *line = NULL;
164 m->sd->charset = (char *)gethval(m, "X-Sun-charset", MAILTOOL);
165
166 if ((line = (char *)gethval(m, "X-Sun-Data-Type", MAILTOOL)) == NULL)
167 {
168 m->sd->type = NEWSTR("TEXT");
169 m->sd->charset = NEWSTR("US-ASCII");
170 }
171 else
172 {
173 while (isspace(*line))
174 line++;
175 if ((m->sd->type = confextr("MAILTOOL", clear_end_space(line), NULL)) == NULL)
176 m->sd->type = NEWSTR("APPLICATION");
177 }
178 /*
179
180 if (matchheader(m, "X-Sun-Data-Type", "text", MAILTOOL))
181 {
182 m->sd->type = NEWSTR("TEXT");
183 m->sd->charset = "ISO-8859-1";
184 m->sd->encoding = E7BIT;
185 }
186 else
187 if (matchheader(m, "X-Sun-Data-Type", "default", MAILTOOL))
188 {
189 m->sd->type = NEWSTR("TEXT");
190 }
191 else
192 if (matchheader(m, "X-Sun-Data-Type", "default-app", MAILTOOL))
193 {
194 m->sd->type = NEWSTR("APPLICATION");
195 }
196 else
197 if (matchheader(m, "X-Sun-Data-Type", "gif-file", MAILTOOL))
198 {
199 m->sd->type = NEWSTR("GIF");
200 }
201 else
202 if (matchheader(m, "X-Sun-Data-Type", "audio-file", MAILTOOL))
203 {
204 m->sd->type = NEWSTR("ULAW");
205 }
206 else
207 m->sd->type = NEWSTR("APPLICATION");
208 */
209 m->sd->encoding = E7BIT;
210 if (matchheader(m, "X-Sun-Encoding-Info", "uuencode", MAILTOOL))
211 {
212 m->sd->encoding = EUUENCODE;
213 }
214 else
215 if (matchheader(m, "X-Sun-Encoding-Info", "binhex", MAILTOOL))
216 {
217 m->sd->encoding = EBINHEX;
218 }
219 else
220 if (matchheader(m, "X-Sun-Encoding-Info", "base64", MAILTOOL))
221 {
222 m->sd->encoding = EBASE64;
223 }
224
225 if (matchheader(m, "X-Sun-Data-Type", "default", MAILTOOL) && m->sd->charset != NULL && m->sd->encoding == E7BIT)
226 {
227 m->sd->type = NEWSTR("TEXT");
228 }
229
230 m->sd->length = string2dec(gethval(m, "X-Sun-Content-length", MAILTOOL));
231 m->sd->bodylines = string2dec(gethval(m, "X-Sun-Content-lines", MAILTOOL));
232 m->sd->description = (char *)gethval(m, "X-Sun-Data-description", MAILTOOL);
233 m->sd->name = (char *)gethval(m, "X-Sun-Data-name", MAILTOOL);
234 }
235 else
236 return (NOK);
237 return (OK);
238 }
239
240 int
get_body_lines(struct data * d)241 get_body_lines(struct data *d)
242 {
243 char *c;
244 int i, e, l;
245
246 l = 0;
247 i = d->bodystart;
248 e = d->bodyend;
249 c = d->contents + i;
250 for (; i < e; i++, c++)
251 if (*c == '\n')
252 l++;
253 return(l);
254 }
255
256