* add 'control context'; which will carry information from control elements into...
[citadel.git] / webcit / msg_renderers.c
1 /*----------------------------------------------------------------------------*/
2 #include "webcit.h"
3 #include "webserver.h"
4
5 /**
6  * message index functions
7  */
8
9
10 void DestroyMimeParts(wc_mime_attachment *Mime)
11 {
12         FreeStrBuf(&Mime->Name);
13         FreeStrBuf(&Mime->FileName);
14         FreeStrBuf(&Mime->PartNum);
15         FreeStrBuf(&Mime->Disposition);
16         FreeStrBuf(&Mime->ContentType);
17         FreeStrBuf(&Mime->Charset);
18         FreeStrBuf(&Mime->Data);
19 }
20
21 void DestroyMime(void *vMime)
22 {
23         wc_mime_attachment *Mime = (wc_mime_attachment*)vMime;
24         DestroyMimeParts(Mime);
25         free(Mime);
26 }
27
28 void DestroyMessageSummary(void *vMsg)
29 {
30         message_summary *Msg = (message_summary*) vMsg;
31
32         FreeStrBuf(&Msg->from);
33         FreeStrBuf(&Msg->to);
34         FreeStrBuf(&Msg->subj);
35         FreeStrBuf(&Msg->reply_inreplyto);
36         FreeStrBuf(&Msg->reply_references);
37         FreeStrBuf(&Msg->cccc);
38         FreeStrBuf(&Msg->hnod);
39         FreeStrBuf(&Msg->AllRcpt);
40         FreeStrBuf(&Msg->Room);
41         FreeStrBuf(&Msg->Rfca);
42         FreeStrBuf(&Msg->OtherNode);
43
44         FreeStrBuf(&Msg->reply_to);
45
46         DeleteHash(&Msg->Attachments);  /**< list of Accachments */
47         DeleteHash(&Msg->Submessages);
48         DeleteHash(&Msg->AttachLinks);
49         DeleteHash(&Msg->AllAttach);
50         free(Msg);
51 }
52
53
54
55 void RegisterMsgHdr(const char *HeaderName, long HdrNLen, ExamineMsgHeaderFunc evaluator, int type)
56 {
57         headereval *ev;
58         ev = (headereval*) malloc(sizeof(headereval));
59         ev->evaluator = evaluator;
60         ev->Type = type;
61         Put(MsgHeaderHandler, HeaderName, HdrNLen, ev, NULL);
62 }
63
64 void RegisterMimeRenderer(const char *HeaderName, long HdrNLen, RenderMimeFunc MimeRenderer)
65 {
66         RenderMimeFuncStruct *f;
67
68         f = (RenderMimeFuncStruct*) malloc(sizeof(RenderMimeFuncStruct));
69         f->f = MimeRenderer;
70         Put(MimeRenderHandler, HeaderName, HdrNLen, f, NULL);
71         
72 }
73
74 /*----------------------------------------------------------------------------*/
75
76 /*
77  *  comparator for two longs in descending order.
78  */
79 int longcmp_r(const void *s1, const void *s2) {
80         long l1;
81         long l2;
82
83         l1 = *(long *)GetSearchPayload(s1);
84         l2 = *(long *)GetSearchPayload(s2);
85
86         if (l1 > l2) return(-1);
87         if (l1 < l2) return(+1);
88         return(0);
89 }
90
91 /*
92  *  comparator for longs; descending order.
93  */
94 int qlongcmp_r(const void *s1, const void *s2) {
95         long l1 = (long) s1;
96         long l2 = (long) s2;
97
98         if (l1 > l2) return(-1);
99         if (l1 < l2) return(+1);
100         return(0);
101 }
102
103  
104 /*
105  * comparator for message summary structs by ascending subject.
106  */
107 int summcmp_subj(const void *s1, const void *s2) {
108         message_summary *summ1;
109         message_summary *summ2;
110         
111         summ1 = (message_summary *)GetSearchPayload(s1);
112         summ2 = (message_summary *)GetSearchPayload(s2);
113         return strcasecmp(ChrPtr(summ1->subj), ChrPtr(summ2->subj));
114 }
115
116 /*
117  * comparator for message summary structs by descending subject.
118  */
119 int summcmp_rsubj(const void *s1, const void *s2) {
120         message_summary *summ1;
121         message_summary *summ2;
122         
123         summ1 = (message_summary *)GetSearchPayload(s1);
124         summ2 = (message_summary *)GetSearchPayload(s2);
125         return strcasecmp(ChrPtr(summ2->subj), ChrPtr(summ1->subj));
126 }
127 /*
128  * comparator for message summary structs by descending subject.
129  */
130 int groupchange_subj(const void *s1, const void *s2) {
131         message_summary *summ1;
132         message_summary *summ2;
133         
134         summ1 = (message_summary *)s1;
135         summ2 = (message_summary *)s2;
136         return ChrPtr(summ2->subj)[0] != ChrPtr(summ1->subj)[0];
137 }
138
139 /*
140  * comparator for message summary structs by ascending sender.
141  */
142 int summcmp_sender(const void *s1, const void *s2) {
143         message_summary *summ1;
144         message_summary *summ2;
145         
146         summ1 = (message_summary *)GetSearchPayload(s1);
147         summ2 = (message_summary *)GetSearchPayload(s2);
148         return strcasecmp(ChrPtr(summ1->from), ChrPtr(summ2->from));
149 }
150
151 /*
152  * comparator for message summary structs by descending sender.
153  */
154 int summcmp_rsender(const void *s1, const void *s2) {
155         message_summary *summ1;
156         message_summary *summ2;
157         
158         summ1 = (message_summary *)GetSearchPayload(s1);
159         summ2 = (message_summary *)GetSearchPayload(s2);
160         return strcasecmp(ChrPtr(summ2->from), ChrPtr(summ1->from));
161 }
162 /*
163  * comparator for message summary structs by descending sender.
164  */
165 int groupchange_sender(const void *s1, const void *s2) {
166         message_summary *summ1;
167         message_summary *summ2;
168         
169         summ1 = (message_summary *)s1;
170         summ2 = (message_summary *)s2;
171         return strcasecmp(ChrPtr(summ2->from), ChrPtr(summ1->from)) != 0;
172
173 }
174
175 /*
176  * comparator for message summary structs by ascending date.
177  */
178 int summcmp_date(const void *s1, const void *s2) {
179         message_summary *summ1;
180         message_summary *summ2;
181         
182         summ1 = (message_summary *)GetSearchPayload(s1);
183         summ2 = (message_summary *)GetSearchPayload(s2);
184
185         if (summ1->date < summ2->date) return -1;
186         else if (summ1->date > summ2->date) return +1;
187         else return 0;
188 }
189
190 /*
191  * comparator for message summary structs by descending date.
192  */
193 int summcmp_rdate(const void *s1, const void *s2) {
194         message_summary *summ1;
195         message_summary *summ2;
196         
197         summ1 = (message_summary *)GetSearchPayload(s1);
198         summ2 = (message_summary *)GetSearchPayload(s2);
199
200         if (summ1->date < summ2->date) return +1;
201         else if (summ1->date > summ2->date) return -1;
202         else return 0;
203 }
204
205 /*
206  * comparator for message summary structs by descending date.
207  */
208 const long DAYSECONDS = 24 * 60 * 60;
209 int groupchange_date(const void *s1, const void *s2) {
210         message_summary *summ1;
211         message_summary *summ2;
212         
213         summ1 = (message_summary *)s1;
214         summ2 = (message_summary *)s2;
215
216         return (summ1->date % DAYSECONDS) != (summ2->date %DAYSECONDS);
217 }
218
219
220 /*----------------------------------------------------------------------------*/
221 /* Don't wanna know... or? */
222 void examine_pref(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset) {return;}
223 void examine_suff(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset) {return;}
224 void examine_path(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset) {return;}
225 void examine_content_encoding(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
226 {
227 /* TODO: do we care? */
228 }
229
230 void examine_nhdr(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
231 {
232         Msg->nhdr = 0;
233         if (!strncasecmp(ChrPtr(HdrLine), "yes", 8))
234                 Msg->nhdr = 1;
235 }
236 int Conditional_ANONYMOUS_MESSAGE(StrBuf *Target, WCTemplputParams *TP)
237 {
238         message_summary *Msg = (message_summary*) CTX;
239         return Msg->nhdr != 0;
240 }
241
242
243 void examine_type(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
244 {
245         Msg->format_type = StrToi(HdrLine);
246                         
247 }
248
249 void examine_from(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
250 {
251         FreeStrBuf(&Msg->from);
252         Msg->from = NewStrBufPlain(NULL, StrLength(HdrLine));
253         StrBuf_RFC822_to_Utf8(Msg->from, HdrLine, WC->DefaultCharset, FoundCharset);
254 }
255 void tmplput_MAIL_SUMM_FROM(StrBuf *Target, WCTemplputParams *TP)
256 {
257         message_summary *Msg = (message_summary*) CTX;
258         StrBufAppendTemplate(Target, TP, Msg->from, 0);
259 }
260
261
262
263 void examine_subj(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
264 {
265         FreeStrBuf(&Msg->subj);
266         Msg->subj = NewStrBufPlain(NULL, StrLength(HdrLine));
267         StrBuf_RFC822_to_Utf8(Msg->subj, HdrLine, WC->DefaultCharset, FoundCharset);
268 }
269 void tmplput_MAIL_SUMM_SUBJECT(StrBuf *Target, WCTemplputParams *TP)
270 {/*////TODO: Fwd: and RE: filter!!*/
271
272         message_summary *Msg = (message_summary*) CTX;
273         StrBufAppendTemplate(Target, TP, Msg->subj, 0);
274 }
275
276
277 void examine_msgn(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
278 {
279         FreeStrBuf(&Msg->reply_inreplyto);
280         Msg->reply_inreplyto = NewStrBufPlain(NULL, StrLength(HdrLine));
281         StrBuf_RFC822_to_Utf8(Msg->reply_inreplyto, HdrLine, WC->DefaultCharset, FoundCharset);
282 }
283 void tmplput_MAIL_SUMM_INREPLYTO(StrBuf *Target, WCTemplputParams *TP)
284 {
285         message_summary *Msg = (message_summary*) CTX;
286         StrBufAppendTemplate(Target, TP, Msg->reply_inreplyto, 0);
287 }
288
289 int Conditional_MAIL_SUMM_UNREAD(StrBuf *Target, WCTemplputParams *TP)
290 {
291         message_summary *Msg = (message_summary*) CTX;
292         return Msg->is_new != 0;
293 }
294
295 void examine_wefw(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
296 {
297         FreeStrBuf(&Msg->reply_references);
298         Msg->reply_references = NewStrBufPlain(NULL, StrLength(HdrLine));
299         StrBuf_RFC822_to_Utf8(Msg->reply_references, HdrLine, WC->DefaultCharset, FoundCharset);
300 }
301 void tmplput_MAIL_SUMM_REFIDS(StrBuf *Target, WCTemplputParams *TP)
302 {
303         message_summary *Msg = (message_summary*) CTX;
304         StrBufAppendTemplate(Target, TP, Msg->reply_references, 0);
305 }
306
307
308 void examine_cccc(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
309 {
310         FreeStrBuf(&Msg->cccc);
311         Msg->cccc = NewStrBufPlain(NULL, StrLength(HdrLine));
312         StrBuf_RFC822_to_Utf8(Msg->cccc, HdrLine, WC->DefaultCharset, FoundCharset);
313         if (Msg->AllRcpt == NULL)
314                 Msg->AllRcpt = NewStrBufPlain(NULL, StrLength(HdrLine));
315         if (StrLength(Msg->AllRcpt) > 0) {
316                 StrBufAppendBufPlain(Msg->AllRcpt, HKEY(", "), 0);
317         }
318         StrBufAppendBuf(Msg->AllRcpt, Msg->cccc, 0);
319 }
320 void tmplput_MAIL_SUMM_CCCC(StrBuf *Target, WCTemplputParams *TP)
321 {
322         message_summary *Msg = (message_summary*) CTX;
323         StrBufAppendTemplate(Target, TP, Msg->cccc, 0);
324 }
325
326
327 void examine_room(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
328 {
329         if ((StrLength(HdrLine) > 0) &&
330             (strcasecmp(ChrPtr(HdrLine), ChrPtr(WC->wc_roomname)))) {
331                 FreeStrBuf(&Msg->Room);
332                 Msg->Room = NewStrBufDup(HdrLine);              
333         }
334 }
335 void tmplput_MAIL_SUMM_ORGROOM(StrBuf *Target, WCTemplputParams *TP)
336 {
337         message_summary *Msg = (message_summary*) CTX;
338         StrBufAppendTemplate(Target, TP, Msg->Room, 0);
339 }
340
341
342 void examine_rfca(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
343 {
344         FreeStrBuf(&Msg->Rfca);
345         Msg->Rfca = NewStrBufDup(HdrLine);
346 }
347 void tmplput_MAIL_SUMM_RFCA(StrBuf *Target, WCTemplputParams *TP)
348 {
349         message_summary *Msg = (message_summary*) CTX;
350         StrBufAppendTemplate(Target, TP, Msg->Rfca, 0);
351 }
352 int Conditional_MAIL_SUMM_RFCA(StrBuf *Target, WCTemplputParams *TP)
353 {
354         message_summary *Msg = (message_summary*) CTX;
355         return StrLength(Msg->Rfca) > 0;
356 }
357
358 void examine_node(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
359 {
360         if ( (StrLength(HdrLine) > 0) &&
361              ((WC->room_flags & QR_NETWORK)
362               || ((strcasecmp(ChrPtr(HdrLine), ChrPtr(serv_info.serv_nodename))
363                    && (strcasecmp(ChrPtr(HdrLine), ChrPtr(serv_info.serv_fqdn))))))) {
364                 FreeStrBuf(&Msg->OtherNode);
365                 Msg->OtherNode = NewStrBufDup(HdrLine);
366         }
367 }
368 void tmplput_MAIL_SUMM_OTHERNODE(StrBuf *Target, WCTemplputParams *TP)
369 {
370         message_summary *Msg = (message_summary*) CTX;
371         StrBufAppendTemplate(Target, TP, Msg->OtherNode, 0);
372 }
373 int Conditional_MAIL_SUMM_OTHERNODE(StrBuf *Target, WCTemplputParams *TP)
374 {
375         message_summary *Msg = (message_summary*) CTX;
376         return StrLength(Msg->OtherNode) > 0;
377 }
378
379
380 void examine_rcpt(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
381 {
382         FreeStrBuf(&Msg->to);
383         Msg->to = NewStrBufPlain(NULL, StrLength(HdrLine));
384         StrBuf_RFC822_to_Utf8(Msg->to, HdrLine, WC->DefaultCharset, FoundCharset);
385         if (Msg->AllRcpt == NULL)
386                 Msg->AllRcpt = NewStrBufPlain(NULL, StrLength(HdrLine));
387         if (StrLength(Msg->AllRcpt) > 0) {
388                 StrBufAppendBufPlain(Msg->AllRcpt, HKEY(", "), 0);
389         }
390         StrBufAppendBuf(Msg->AllRcpt, Msg->to, 0);
391 }
392 void tmplput_MAIL_SUMM_TO(StrBuf *Target, WCTemplputParams *TP)
393 {
394         message_summary *Msg = (message_summary*) CTX;
395         StrBufAppendTemplate(Target, TP, Msg->to, 0);
396 }
397 void tmplput_MAIL_SUMM_ALLRCPT(StrBuf *Target, WCTemplputParams *TP)
398 {
399         message_summary *Msg = (message_summary*) CTX;
400         StrBufAppendTemplate(Target, TP, Msg->AllRcpt, 0);
401 }
402
403
404 HashList *iterate_get_mailsumm_All(StrBuf *Target, WCTemplputParams *TP)
405 {
406         return WC->summ;
407 }
408 int Conditional_ROOM_DISPLAY_MSG(StrBuf *Target, WCTemplputParams *TP) {
409         long num_inset;
410         wcsubst *subst;
411         wcsession *WCC = WC;
412   
413         if (GetHash(WCC->vars, HKEY("ITERATE:N"), (void *)&subst) && 
414             (subst != NULL)) {
415                 num_inset = subst->lvalue;
416                 if ((num_inset >= WC->startmsg) && (WCC->num_displayed <= WCC->maxmsgs)) {
417                         WCC->num_displayed = WCC->num_displayed+1;
418                         return 1; /* Pass GO, collect $200 */
419                 } 
420         }
421         return 0;
422 }
423 int Conditional_MAIL_SUMM_LASTMSG(StrBuf *Target, WCTemplputParams *TP) {
424         wcsubst *nsubst;
425         long is_last_n = 0;
426   
427         if (GetHash(WC->vars, HKEY("ITERATE:LASTN"), (void *)&nsubst) &&
428             (nsubst != NULL)) {
429                 is_last_n = nsubst->lvalue;
430 /*
431         //GetHash(WC->vars, HKEY("ITERATE:N"), (void *)&n_dsubst);
432         //num_inset = n_dsubst->lvalue;
433         */
434         /* Is the num_displayed higher than maxmsgs? OR last in iterator */
435         }
436         return ((WC->num_displayed > WC->maxmsgs) || (is_last_n == 1));
437 }
438 void examine_time(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
439 {
440         Msg->date = StrTol(HdrLine);
441 }
442
443 void tmplput_MAIL_SUMM_DATE_BRIEF(StrBuf *Target, WCTemplputParams *TP)
444 {
445         char datebuf[64];
446         message_summary *Msg = (message_summary*) CTX;
447         webcit_fmt_date(datebuf, Msg->date, 1);
448         StrBufAppendBufPlain(Target, datebuf, -1, 0);
449 }
450
451 void tmplput_MAIL_SUMM_DATE_FULL(StrBuf *Target, WCTemplputParams *TP)
452 {
453         char datebuf[64];
454         message_summary *Msg = (message_summary*) CTX;
455         webcit_fmt_date(datebuf, Msg->date, 0);
456         StrBufAppendBufPlain(Target, datebuf, -1, 0);
457 }
458 void tmplput_MAIL_SUMM_DATE_NO(StrBuf *Target, WCTemplputParams *TP)
459 {
460         message_summary *Msg = (message_summary*) CTX;
461         StrBufAppendPrintf(Target, "%ld", Msg->date, 0);
462 }
463
464
465
466 void render_MAIL(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCharset)
467 {
468         Mime->Data = NewStrBufPlain(NULL, Mime->length);
469         read_message(Mime->Data, HKEY("view_submessage"), Mime->msgnum, 0, Mime->PartNum);
470 /*
471         if ( (!IsEmptyStr(mime_submessages)) && (!section[0]) ) {
472                 for (i=0; i<num_tokens(mime_submessages, '|'); ++i) {
473                         extract_token(buf, mime_submessages, i, '|', sizeof buf);
474                         / ** use printable_view to suppress buttons * /
475                         wprintf("<blockquote>");
476                         read_message(Mime->msgnum, 1, ChrPtr(Mime->Section));
477                         wprintf("</blockquote>");
478                 }
479         }
480 */
481 }
482
483 void render_MIME_VCard(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCharset)
484 {
485         wcsession *WCC = WC;
486         MimeLoadData(Mime);
487         if (StrLength(Mime->Data) > 0) {
488                 StrBuf *Buf;
489                 Buf = NewStrBuf();
490                 /** If it's my vCard I can edit it */
491                 if (    (!strcasecmp(ChrPtr(WCC->wc_roomname), USERCONFIGROOM))
492                         || (!strcasecmp(&(ChrPtr(WCC->wc_roomname)[11]), USERCONFIGROOM))
493                         || (WC->wc_view == VIEW_ADDRESSBOOK)
494                         ) {
495                         StrBufAppendPrintf(Buf, "<a href=\"edit_vcard?msgnum=%ld&partnum=%s\">",
496                                 Mime->msgnum, ChrPtr(Mime->PartNum));
497                         StrBufAppendPrintf(Buf, "[%s]</a>", _("edit"));
498                 }
499
500                 /* In all cases, display the full card */
501                 display_vcard(Buf, ChrPtr(Mime->Data), 0, 1, NULL, Mime->msgnum);
502                 FreeStrBuf(&Mime->Data);
503                 Mime->Data = Buf;
504         }
505
506 }
507
508 void render_MIME_ICS(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCharset)
509 {
510         if (StrLength(Mime->Data) == 0) {
511                 MimeLoadData(Mime);
512         }
513         if (StrLength(Mime->Data) > 0) {
514                 cal_process_attachment(Mime);
515         }
516 }
517
518
519
520 void examine_mime_part(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
521 {
522         wc_mime_attachment *Mime;
523         StrBuf *Buf;
524         
525         Mime = (wc_mime_attachment*) malloc(sizeof(wc_mime_attachment));
526         memset(Mime, 0, sizeof(wc_mime_attachment));
527         Mime->msgnum = Msg->msgnum;
528         Buf = NewStrBuf();
529
530         Mime->Name = NewStrBuf();
531         StrBufExtract_token(Buf, HdrLine, 0, '|');
532         StrBuf_RFC822_to_Utf8(Mime->Name, Buf, WC->DefaultCharset, FoundCharset);
533         StrBufTrim(Mime->Name);
534
535         StrBufExtract_token(Buf, HdrLine, 1, '|');
536         Mime->FileName = NewStrBuf();
537         StrBuf_RFC822_to_Utf8(Mime->FileName, Buf, WC->DefaultCharset, FoundCharset);
538         StrBufTrim(Mime->FileName);
539
540         Mime->PartNum = NewStrBuf();
541         StrBufExtract_token(Mime->PartNum, HdrLine, 2, '|');
542         StrBufTrim(Mime->PartNum);
543         if (strchr(ChrPtr(Mime->PartNum), '.') != NULL)
544                 Mime->level = 2;
545         else
546                 Mime->level = 1;
547
548         Mime->Disposition = NewStrBuf();
549         StrBufExtract_token(Mime->Disposition, HdrLine, 3, '|');
550
551         Mime->ContentType = NewStrBuf();
552         StrBufExtract_token(Mime->ContentType, HdrLine, 4, '|');
553         StrBufTrim(Mime->ContentType);
554         StrBufLowerCase(Mime->ContentType);
555
556         Mime->length = StrBufExtract_int(HdrLine, 5, '|');
557
558         if ( (StrLength(Mime->FileName) == 0) && (StrLength(Mime->Name) > 0) ) {
559                 StrBufAppendBuf(Mime->FileName, Mime->Name, 0);
560         }
561
562         if (StrLength(Msg->PartNum) > 0) {
563                 StrBuf *tmp;
564                 StrBufPrintf(Buf, "%s.%s", ChrPtr(Msg->PartNum), ChrPtr(Mime->PartNum));
565                 tmp = Mime->PartNum;
566                 Mime->PartNum = Buf;
567                 Buf = tmp;
568         }
569
570         if (Msg->AllAttach == NULL)
571                 Msg->AllAttach = NewHash(1,NULL);
572         Put(Msg->AllAttach, SKEY(Mime->PartNum), Mime, DestroyMime);
573         FreeStrBuf(&Buf);
574 }
575
576
577 void evaluate_mime_part(message_summary *Msg, wc_mime_attachment *Mime)
578 {
579         void *vMimeRenderer;
580
581         /* just print the root-node */
582         if ((Mime->level == 1) &&
583             GetHash(MimeRenderHandler, SKEY(Mime->ContentType), &vMimeRenderer) &&
584             vMimeRenderer != NULL)
585         {
586                 Mime->Renderer = (RenderMimeFuncStruct*) vMimeRenderer;
587                 if (Msg->Submessages == NULL)
588                         Msg->Submessages = NewHash(1,NULL);
589                 Put(Msg->Submessages, SKEY(Mime->PartNum), Mime, reference_free_handler);
590         }
591         else if ((Mime->level == 1) &&
592                  (!strcasecmp(ChrPtr(Mime->Disposition), "inline"))
593                  && (!strncasecmp(ChrPtr(Mime->ContentType), "image/", 6)) ){
594                 if (Msg->AttachLinks == NULL)
595                         Msg->AttachLinks = NewHash(1,NULL);
596                 Put(Msg->AttachLinks, SKEY(Mime->PartNum), Mime, reference_free_handler);
597         }
598         else if ((Mime->level == 1) &&
599                  (StrLength(Mime->ContentType) > 0) &&
600                   ( (!strcasecmp(ChrPtr(Mime->Disposition), "attachment")) 
601                     || (!strcasecmp(ChrPtr(Mime->Disposition), "inline"))
602                     || (!strcasecmp(ChrPtr(Mime->Disposition), ""))))
603         {               
604                 if (Msg->AttachLinks == NULL)
605                         Msg->AttachLinks = NewHash(1,NULL);
606                 Put(Msg->AttachLinks, SKEY(Mime->PartNum), Mime, reference_free_handler);
607                 if ((strcasecmp(ChrPtr(Mime->ContentType), "application/octet-stream") == 0) && 
608                     (StrLength(Mime->FileName) > 0)) {
609                         FlushStrBuf(Mime->ContentType);
610                         StrBufAppendBufPlain(Mime->ContentType,
611                                              GuessMimeByFilename(SKEY(Mime->FileName)),
612                                              -1, 0);
613                 }
614         }
615 }
616
617 void tmplput_MAIL_SUMM_NATTACH(StrBuf *Target, WCTemplputParams *TP)
618 {
619         message_summary *Msg = (message_summary*) CTX;
620         StrBufAppendPrintf(Target, "%ld", GetCount(Msg->Attachments));
621 }
622
623
624 void examine_hnod(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
625 {
626         FreeStrBuf(&Msg->hnod);
627         Msg->hnod = NewStrBufPlain(NULL, StrLength(HdrLine));
628         StrBuf_RFC822_to_Utf8(Msg->hnod, HdrLine, WC->DefaultCharset, FoundCharset);
629 }
630 void tmplput_MAIL_SUMM_H_NODE(StrBuf *Target, WCTemplputParams *TP)
631 {
632         message_summary *Msg = (message_summary*) CTX;
633         StrBufAppendTemplate(Target, TP, Msg->hnod, 0);
634 }
635 int Conditional_MAIL_SUMM_H_NODE(StrBuf *Target, WCTemplputParams *TP)
636 {
637         message_summary *Msg = (message_summary*) CTX;
638         return StrLength(Msg->hnod) > 0;
639 }
640
641
642
643 void examine_text(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
644 {
645         Msg->MsgBody->Data = NewStrBuf();
646 }
647
648 void examine_msg4_partnum(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
649 {
650         Msg->MsgBody->PartNum = NewStrBufDup(HdrLine);
651         StrBufTrim(Msg->MsgBody->PartNum);
652 }
653
654 void examine_content_lengh(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
655 {
656         Msg->MsgBody->length = StrTol(HdrLine);
657         Msg->MsgBody->size_known = 1;
658 }
659
660 void examine_content_type(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
661 {
662         void *vHdr;
663         headereval *Hdr;
664         StrBuf *Token;
665         StrBuf *Value;
666         const char* sem;
667         const char *eq;
668         int len;
669         StrBufTrim(HdrLine);
670         Msg->MsgBody->ContentType = NewStrBufDup(HdrLine);
671         sem = strchr(ChrPtr(HdrLine), ';');
672
673         if (sem != NULL) {
674                 Token = NewStrBufPlain(NULL, StrLength(HdrLine));
675                 Value = NewStrBufPlain(NULL, StrLength(HdrLine));
676                 len = sem - ChrPtr(HdrLine);
677                 StrBufCutAt(Msg->MsgBody->ContentType, len, NULL);
678                 while (sem != NULL) {
679                         while (isspace(*(sem + 1)))
680                                 sem ++;
681                         StrBufCutLeft(HdrLine, sem - ChrPtr(HdrLine));
682                         sem = strchr(ChrPtr(HdrLine), ';');
683                         if (sem != NULL)
684                                 len = sem - ChrPtr(HdrLine);
685                         else
686                                 len = StrLength(HdrLine);
687                         FlushStrBuf(Token);
688                         FlushStrBuf(Value);
689                         StrBufAppendBufPlain(Token, ChrPtr(HdrLine), len, 0);
690                         eq = strchr(ChrPtr(Token), '=');
691                         if (eq != NULL) {
692                                 len = eq - ChrPtr(Token);
693                                 StrBufAppendBufPlain(Value, eq + 1, StrLength(Token) - len - 1, 0); 
694                                 StrBufCutAt(Token, len, NULL);
695                                 StrBufTrim(Value);
696                         }
697                         StrBufTrim(Token);
698
699                         if (GetHash(MsgHeaderHandler, SKEY(Token), &vHdr) &&
700                             (vHdr != NULL)) {
701                                 Hdr = (headereval*)vHdr;
702                                 Hdr->evaluator(Msg, Value, FoundCharset);
703                         }
704                         else lprintf(1, "don't know how to handle content type sub-header[%s]\n", ChrPtr(Token));
705                 }
706                 FreeStrBuf(&Token);
707                 FreeStrBuf(&Value);
708         }
709 }
710
711 void tmplput_MAIL_SUMM_N(StrBuf *Target, WCTemplputParams *TP)
712 {
713         message_summary *Msg = (message_summary*) CTX;
714         StrBufAppendPrintf(Target, "%ld", Msg->msgnum);
715 }
716
717
718
719 int Conditional_MAIL_MIME_ALL(StrBuf *Target, WCTemplputParams *TP)
720 {
721         message_summary *Msg = (message_summary*) CTX;
722         return GetCount(Msg->Attachments) > 0;
723 }
724
725 int Conditional_MAIL_MIME_SUBMESSAGES(StrBuf *Target, WCTemplputParams *TP)
726 {
727         message_summary *Msg = (message_summary*) CTX;
728         return GetCount(Msg->Submessages) > 0;
729 }
730
731 int Conditional_MAIL_MIME_ATTACHLINKS(StrBuf *Target, WCTemplputParams *TP)
732 {
733         message_summary *Msg = (message_summary*) CTX;
734         return GetCount(Msg->AttachLinks) > 0;
735 }
736
737 int Conditional_MAIL_MIME_ATTACH(StrBuf *Target, WCTemplputParams *TP)
738 {
739         message_summary *Msg = (message_summary*) CTX;
740         return GetCount(Msg->AllAttach) > 0;
741 }
742
743
744
745 /*----------------------------------------------------------------------------*/
746 void tmplput_QUOTED_MAIL_BODY(StrBuf *Target, WCTemplputParams *TP)
747 {
748         long MsgNum;
749         StrBuf *Buf;
750
751         MsgNum = LBstr(TKEY(0));
752         Buf = NewStrBuf();
753         read_message(Buf, HKEY("view_message_replyquote"), MsgNum, 0, NULL);
754         StrBufAppendTemplate(Target, TP, Buf, 1);
755         FreeStrBuf(&Buf);
756 }
757
758 void tmplput_MAIL_BODY(StrBuf *Target, WCTemplputParams *TP)
759 {
760         message_summary *Msg = (message_summary*) CTX;
761         StrBufAppendTemplate(Target, TP, Msg->MsgBody->Data, 0);
762 }
763
764
765 void render_MAIL_variformat(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCharset)
766 {
767         /* Messages in legacy Citadel variformat get handled thusly... */
768         StrBuf *Target = NewStrBufPlain(NULL, StrLength(Mime->Data));
769         FmOut(Target, "JUSTIFY", Mime->Data);
770         FreeStrBuf(&Mime->Data);
771         Mime->Data = Target;
772 }
773
774 void render_MAIL_text_plain(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCharset)
775 {
776         StrBuf *cs = NULL;
777         const char *ptr, *pte;
778         const char *BufPtr = NULL;
779         StrBuf *Line;
780         StrBuf *Line1;
781         StrBuf *Line2;
782         StrBuf *Target;
783
784         int ConvertIt = 1;
785         int bn = 0;
786         int bq = 0;
787         int i, n, done = 0;
788         long len;
789 #ifdef HAVE_ICONV
790         iconv_t ic = (iconv_t)(-1) ;
791 #endif
792
793         if ((StrLength(Mime->Data) == 0) && (Mime->length > 0)) {
794                 FreeStrBuf(&Mime->Data);
795                 Mime->Data = NewStrBufPlain(NULL, Mime->length);
796                 if (!read_message(Mime->Data, HKEY("view_submessage"), Mime->msgnum, 0, Mime->PartNum))
797                         return;
798         }
799
800         /* Boring old 80-column fixed format text gets handled this way... */
801         if ((strcasecmp(ChrPtr(Mime->Charset), "us-ascii") == 0) &&
802             (strcasecmp(ChrPtr(Mime->Charset), "UTF-8") == 0))
803                 ConvertIt = 0;
804
805 #ifdef HAVE_ICONV
806         if (ConvertIt) {
807                 if (StrLength(Mime->Charset) != 0)
808                         cs = Mime->Charset;
809                 else if (StrLength(FoundCharset) > 0)
810                         cs = FoundCharset;
811                 else if (StrLength(WC->DefaultCharset) > 0)
812                         cs = WC->DefaultCharset;
813                 if (cs == NULL) {
814                         ConvertIt = 0;
815                 }
816                 else {
817                         ctdl_iconv_open("UTF-8", ChrPtr(cs), &ic);
818                         if (ic == (iconv_t)(-1) ) {
819                                 lprintf(5, "%s:%d iconv_open(UTF-8, %s) failed: %s\n",
820                                         __FILE__, __LINE__, ChrPtr(Mime->Charset), strerror(errno));
821                         }
822                 }
823         }
824 #endif
825         Line = NewStrBuf();
826         Line1 = NewStrBuf();
827         Line2 = NewStrBuf();
828         Target = NewStrBufPlain(NULL, StrLength(Mime->Data));
829
830         while ((n = StrBufSipLine(Line, Mime->Data, &BufPtr), n >= 0) && !done)
831         {
832                 done = n == 0;
833                 bq = 0;
834                 i = 0;
835                 ptr = ChrPtr(Line);
836                 len = StrLength(Line);
837                 pte = ptr + len;
838                 
839                 while ((ptr < pte) &&
840                        ((*ptr == '>') ||
841                         isspace(*ptr)))
842                 {
843                         if (*ptr == '>')
844                                 bq++;
845                         ptr ++;
846                         i++;
847                 }
848                 if (i > 0) StrBufCutLeft(Line, i);
849                 
850                 if (StrLength(Line) == 0)
851                         continue;
852
853                 for (i = bn; i < bq; i++)                               
854                         StrBufAppendBufPlain(Target, HKEY("<blockquote>"), 0);
855                 for (i = bq; i < bn; i++)                               
856                         StrBufAppendBufPlain(Target, HKEY("</blockquote>"), 0);
857
858                 if (ConvertIt == 1) {
859                         StrBufConvert(Line, Line1, &ic);
860                 }
861
862                 StrBufAppendBufPlain(Target, HKEY("<tt>"), 0);
863                 UrlizeText(Line1, Line, Line2);
864
865                 StrEscAppend(Target, Line1, NULL, 0, 0);
866                 StrBufAppendBufPlain(Target, HKEY("</tt><br />\n"), 0);
867                 bn = bq;
868         }
869
870         for (i = 0; i < bn; i++)                                
871                 StrBufAppendBufPlain(Target, HKEY("</blockquote>"), 0);
872
873         StrBufAppendBufPlain(Target, HKEY("</i><br />"), 0);
874 #ifdef HAVE_ICONV
875         if (ic != (iconv_t)(-1) ) {
876                 iconv_close(ic);
877         }
878 #endif
879         FreeStrBuf(&Mime->Data);
880         Mime->Data = Target;
881         FreeStrBuf(&Line);
882         FreeStrBuf(&Line1);
883         FreeStrBuf(&Line2);
884 }
885
886 void render_MAIL_html(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCharset)
887 {
888         StrBuf *Buf;
889
890         if (StrLength(Mime->Data) == 0)
891                 return;
892
893         Buf = NewStrBufPlain(NULL, StrLength(Mime->Data));
894
895         /* HTML is fun, but we've got to strip it first */
896         output_html(ChrPtr(Mime->Charset), 
897                     (WC->wc_view == VIEW_WIKI ? 1 : 0), 
898                     StrToi(Mime->PartNum), 
899                     Mime->Data, Buf);
900         FreeStrBuf(&Mime->Data);
901         Mime->Data = Buf;
902 }
903
904 void render_MAIL_UNKNOWN(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCharset)
905 {
906         /* Unknown weirdness */
907         FlushStrBuf(Mime->Data);
908         StrBufAppendBufPlain(Mime->Data, _("I don't know how to display "), -1, 0);
909         StrBufAppendBuf(Mime->Data, Mime->ContentType, 0);
910         StrBufAppendBufPlain(Mime->Data, HKEY("<br />\n"), 0);
911 }
912
913
914
915
916
917
918 HashList *iterate_get_mime_All(StrBuf *Target, WCTemplputParams *TP)
919 {
920         message_summary *Msg = (message_summary*) CTX;
921         return Msg->Attachments;
922 }
923 HashList *iterate_get_mime_Submessages(StrBuf *Target, WCTemplputParams *TP)
924 {
925         message_summary *Msg = (message_summary*) CTX;
926         return Msg->Submessages;
927 }
928 HashList *iterate_get_mime_AttachLinks(StrBuf *Target, WCTemplputParams *TP)
929 {
930         message_summary *Msg = (message_summary*) CTX;
931         return Msg->AttachLinks;
932 }
933 HashList *iterate_get_mime_Attachments(StrBuf *Target, WCTemplputParams *TP)
934 {
935         message_summary *Msg = (message_summary*) CTX;
936         return Msg->AllAttach;
937 }
938
939 void tmplput_MIME_Name(StrBuf *Target, WCTemplputParams *TP)
940 {
941         wc_mime_attachment *mime = (wc_mime_attachment*) CTX;
942         StrBufAppendTemplate(Target, TP, mime->Name, 0);
943 }
944
945 void tmplput_MIME_FileName(StrBuf *Target, WCTemplputParams *TP)
946 {
947         wc_mime_attachment *mime = (wc_mime_attachment*) CTX;
948         StrBufAppendTemplate(Target, TP, mime->FileName, 0);
949 }
950
951 void tmplput_MIME_PartNum(StrBuf *Target, WCTemplputParams *TP)
952 {
953         wc_mime_attachment *mime = (wc_mime_attachment*) CTX;
954         StrBufAppendTemplate(Target, TP, mime->PartNum, 0);
955 }
956
957 void tmplput_MIME_MsgNum(StrBuf *Target, WCTemplputParams *TP)
958 {
959         wc_mime_attachment *mime = (wc_mime_attachment*) CTX;
960         StrBufAppendPrintf(Target, "%ld", mime->msgnum);
961 }
962
963 void tmplput_MIME_Disposition(StrBuf *Target, WCTemplputParams *TP)
964 {
965         wc_mime_attachment *mime = (wc_mime_attachment*) CTX;
966         StrBufAppendTemplate(Target, TP, mime->Disposition, 0);
967 }
968
969 void tmplput_MIME_ContentType(StrBuf *Target, WCTemplputParams *TP)
970 {
971         wc_mime_attachment *mime = (wc_mime_attachment*) CTX;
972         StrBufAppendTemplate(Target, TP, mime->ContentType, 0);
973 }
974
975 void examine_charset(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
976 {
977         Msg->MsgBody->Charset = NewStrBufDup(HdrLine);
978 }
979
980 void tmplput_MIME_Charset(StrBuf *Target, WCTemplputParams *TP)
981 {
982         wc_mime_attachment *mime = (wc_mime_attachment*) CTX;
983         StrBufAppendTemplate(Target, TP, mime->Charset, 0);
984 }
985
986 void tmplput_MIME_Data(StrBuf *Target, WCTemplputParams *TP)
987 {
988         wc_mime_attachment *mime = (wc_mime_attachment*) CTX;
989         if (mime->Renderer != NULL)
990                 mime->Renderer->f(mime, NULL, NULL);
991         StrBufAppendTemplate(Target, TP, mime->Data, 0);
992         /* TODO: check whether we need to load it now? */
993 }
994
995 void tmplput_MIME_LoadData(StrBuf *Target, WCTemplputParams *TP)
996 {
997         wcsession *WCC = WC;    
998         wc_mime_attachment *mime = (wc_mime_attachment*) CTX;
999         wc_mime_attachment *att;
1000         
1001         if ( (!strcasecmp(ChrPtr(mime->Disposition), "inline"))||
1002              (!strcasecmp(ChrPtr(mime->Disposition), "attachment")) ) 
1003         {
1004                 
1005                 int n;
1006                 char N[64];
1007                 /* steal this mime part... */
1008                 att = malloc(sizeof(wc_mime_attachment));
1009                 memcpy(att, mime, sizeof(wc_mime_attachment));
1010                 memset(mime, 0, sizeof(wc_mime_attachment));
1011
1012                 if (att->Data == NULL) 
1013                         MimeLoadData(att);
1014
1015                 if (WCC->attachments == NULL)
1016                         WCC->attachments = NewHash(1, NULL);
1017                 /* And add it to the list. */
1018                 n = snprintf(N, sizeof N, "%d", GetCount(WCC->attachments) + 1);
1019                 Put(WCC->attachments, N, n, att, DestroyMime);
1020         }
1021 }
1022
1023 void tmplput_MIME_Length(StrBuf *Target, WCTemplputParams *TP)
1024 {
1025         wc_mime_attachment *mime = (wc_mime_attachment*) CTX;
1026         StrBufAppendPrintf(Target, "%ld", mime->length);
1027 }
1028
1029 HashList *iterate_get_registered_Attachments(StrBuf *Target, WCTemplputParams *TP)
1030 {
1031         return WC->attachments;
1032 }
1033
1034 void servcmd_do_search(char *buf, long bufsize)
1035 {
1036         snprintf(buf, bufsize, "MSGS SEARCH|%s", bstr("query"));
1037 }
1038
1039 void servcmd_headers(char *buf, long bufsize)
1040 {
1041         snprintf(buf, bufsize, "MSGS ALL");
1042 }
1043
1044 void servcmd_readfwd(char *buf, long bufsize)
1045 {
1046         snprintf(buf, bufsize, "MSGS ALL");
1047 }
1048
1049 void servcmd_readnew(char *buf, long bufsize)
1050 {
1051         snprintf(buf, bufsize, "MSGS NEW");
1052 }
1053
1054 void servcmd_readold(char *buf, long bufsize)
1055 {
1056         snprintf(buf, bufsize, "MSGS OLD");
1057 }
1058
1059
1060 readloop_struct rlid[] = {
1061         { {HKEY("do_search")}, servcmd_do_search},
1062         { {HKEY("headers")},   servcmd_headers},
1063         { {HKEY("readfwd")},   servcmd_readfwd},
1064         { {HKEY("readnew")},   servcmd_readnew},
1065         { {HKEY("readold")},   servcmd_readold}
1066 };
1067
1068
1069
1070 void SetAccessCommand(long Oper)
1071 {
1072         wcsession *WCC = WC;    
1073
1074         if (WCC->UrlFragment1 != NULL ) {
1075                 FlushStrBuf(WCC->UrlFragment1);
1076                 StrBufAppendBufPlain(WCC->UrlFragment1, 
1077                                      rlid[Oper].name.Key, rlid[Oper].name.len, 0);
1078         }
1079         else 
1080                 WCC->UrlFragment1 = NewStrBufPlain(rlid[Oper].name.Key, rlid[Oper].name.len);
1081 }
1082                 
1083
1084
1085
1086
1087 void 
1088 InitModule_MSGRENDERERS
1089 (void)
1090 {
1091         RegisterSortFunc(HKEY("date"), 
1092                          NULL, 0,
1093                          summcmp_date,
1094                          summcmp_rdate,
1095                          groupchange_date,
1096                          CTX_MAILSUM);
1097         RegisterSortFunc(HKEY("subject"), 
1098                          NULL, 0,
1099                          summcmp_subj,
1100                          summcmp_rsubj,
1101                          groupchange_subj,
1102                          CTX_MAILSUM);
1103         RegisterSortFunc(HKEY("sender"),
1104                          NULL, 0,
1105                          summcmp_sender,
1106                          summcmp_rsender,
1107                          groupchange_sender,
1108                          CTX_MAILSUM);
1109
1110         /* iterate over all known mails in WC->summ */
1111         RegisterIterator("MAIL:SUMM:MSGS", 0, NULL, iterate_get_mailsumm_All,
1112                          NULL,NULL, CTX_MAILSUM, CTX_NONE, IT_NOFLAG);
1113
1114         RegisterNamespace("MAIL:SUMM:DATEBRIEF", 0, 0, tmplput_MAIL_SUMM_DATE_BRIEF, CTX_MAILSUM);
1115         RegisterNamespace("MAIL:SUMM:DATEFULL", 0, 0, tmplput_MAIL_SUMM_DATE_FULL, CTX_MAILSUM);
1116         RegisterNamespace("MAIL:SUMM:DATENO",  0, 0, tmplput_MAIL_SUMM_DATE_NO,  CTX_MAILSUM);
1117         RegisterNamespace("MAIL:SUMM:N",       0, 0, tmplput_MAIL_SUMM_N,        CTX_MAILSUM);
1118         RegisterNamespace("MAIL:SUMM:FROM",    0, 2, tmplput_MAIL_SUMM_FROM,     CTX_MAILSUM);
1119         RegisterNamespace("MAIL:SUMM:TO",      0, 2, tmplput_MAIL_SUMM_TO,       CTX_MAILSUM);
1120         RegisterNamespace("MAIL:SUMM:SUBJECT", 0, 4, tmplput_MAIL_SUMM_SUBJECT,  CTX_MAILSUM);
1121         RegisterNamespace("MAIL:SUMM:NTATACH", 0, 0, tmplput_MAIL_SUMM_NATTACH,  CTX_MAILSUM);
1122         RegisterNamespace("MAIL:SUMM:CCCC", 0, 2, tmplput_MAIL_SUMM_CCCC,  CTX_MAILSUM);
1123         RegisterNamespace("MAIL:SUMM:H_NODE", 0, 2, tmplput_MAIL_SUMM_H_NODE,  CTX_MAILSUM);
1124         RegisterNamespace("MAIL:SUMM:ALLRCPT", 0, 2, tmplput_MAIL_SUMM_ALLRCPT,  CTX_MAILSUM);
1125         RegisterNamespace("MAIL:SUMM:ORGROOM", 0, 2, tmplput_MAIL_SUMM_ORGROOM,  CTX_MAILSUM);
1126         RegisterNamespace("MAIL:SUMM:RFCA", 0, 2, tmplput_MAIL_SUMM_RFCA,  CTX_MAILSUM);
1127         RegisterNamespace("MAIL:SUMM:OTHERNODE", 2, 0, tmplput_MAIL_SUMM_OTHERNODE,  CTX_MAILSUM);
1128         RegisterNamespace("MAIL:SUMM:REFIDS", 0, 0, tmplput_MAIL_SUMM_REFIDS,  CTX_MAILSUM);
1129         RegisterNamespace("MAIL:SUMM:INREPLYTO", 0, 2, tmplput_MAIL_SUMM_INREPLYTO,  CTX_MAILSUM);
1130         RegisterNamespace("MAIL:BODY", 0, 2, tmplput_MAIL_BODY,  CTX_MAILSUM);
1131         RegisterNamespace("MAIL:QUOTETEXT", 1, 2, tmplput_QUOTED_MAIL_BODY,  CTX_NONE);
1132         RegisterConditional(HKEY("COND:ROOM:DISPLAYMSG"), 0, Conditional_ROOM_DISPLAY_MSG, CTX_MAILSUM);
1133         RegisterConditional(HKEY("COND:MAIL:SUMM:LASTMSG"), 0, Conditional_MAIL_SUMM_LASTMSG, CTX_MAILSUM);
1134         RegisterConditional(HKEY("COND:MAIL:SUMM:RFCA"), 0, Conditional_MAIL_SUMM_RFCA,  CTX_MAILSUM);
1135         RegisterConditional(HKEY("COND:MAIL:SUMM:UNREAD"), 0, Conditional_MAIL_SUMM_UNREAD, CTX_MAILSUM);
1136         RegisterConditional(HKEY("COND:MAIL:SUMM:H_NODE"), 0, Conditional_MAIL_SUMM_H_NODE, CTX_MAILSUM);
1137         RegisterConditional(HKEY("COND:MAIL:SUMM:OTHERNODE"), 0, Conditional_MAIL_SUMM_OTHERNODE, CTX_MAILSUM);
1138         RegisterConditional(HKEY("COND:MAIL:ANON"), 0, Conditional_ANONYMOUS_MESSAGE, CTX_MAILSUM);
1139
1140
1141         /* do we have mimetypes to iterate over? */
1142         RegisterConditional(HKEY("COND:MAIL:MIME:ATTACH"), 0, Conditional_MAIL_MIME_ALL, CTX_MAILSUM);
1143         RegisterConditional(HKEY("COND:MAIL:MIME:ATTACH:SUBMESSAGES"), 0, Conditional_MAIL_MIME_SUBMESSAGES, CTX_MAILSUM);
1144         RegisterConditional(HKEY("COND:MAIL:MIME:ATTACH:LINKS"), 0, Conditional_MAIL_MIME_ATTACHLINKS, CTX_MAILSUM);
1145         RegisterConditional(HKEY("COND:MAIL:MIME:ATTACH:ATT"), 0, Conditional_MAIL_MIME_ATTACH, CTX_MAILSUM);
1146         RegisterIterator("MAIL:MIME:ATTACH", 0, NULL, iterate_get_mime_All, 
1147                          NULL, NULL, CTX_MIME_ATACH, CTX_MAILSUM, IT_NOFLAG);
1148         RegisterIterator("MAIL:MIME:ATTACH:SUBMESSAGES", 0, NULL, iterate_get_mime_Submessages, 
1149                          NULL, NULL, CTX_MIME_ATACH, CTX_MAILSUM, IT_NOFLAG);
1150         RegisterIterator("MAIL:MIME:ATTACH:LINKS", 0, NULL, iterate_get_mime_AttachLinks, 
1151                          NULL, NULL, CTX_MIME_ATACH, CTX_MAILSUM, IT_NOFLAG);
1152         RegisterIterator("MAIL:MIME:ATTACH:ATT", 0, NULL, iterate_get_mime_Attachments, 
1153                          NULL, NULL, CTX_MIME_ATACH, CTX_MAILSUM, IT_NOFLAG);
1154
1155         /* Parts of a mime attachent */
1156         RegisterNamespace("MAIL:MIME:NAME", 0, 2, tmplput_MIME_Name, CTX_MIME_ATACH);
1157         RegisterNamespace("MAIL:MIME:FILENAME", 0, 2, tmplput_MIME_FileName, CTX_MIME_ATACH);
1158         RegisterNamespace("MAIL:MIME:PARTNUM", 0, 2, tmplput_MIME_PartNum, CTX_MIME_ATACH);
1159         RegisterNamespace("MAIL:MIME:MSGNUM", 0, 2, tmplput_MIME_MsgNum, CTX_MIME_ATACH);
1160         RegisterNamespace("MAIL:MIME:DISPOSITION", 0, 2, tmplput_MIME_Disposition, CTX_MIME_ATACH);
1161         RegisterNamespace("MAIL:MIME:CONTENTTYPE", 0, 2, tmplput_MIME_ContentType, CTX_MIME_ATACH);
1162         RegisterNamespace("MAIL:MIME:CHARSET", 0, 2, tmplput_MIME_Charset, CTX_MIME_ATACH);
1163         RegisterNamespace("MAIL:MIME:LENGTH", 0, 2, tmplput_MIME_Length, CTX_MIME_ATACH);
1164         RegisterNamespace("MAIL:MIME:DATA", 0, 2, tmplput_MIME_Data, CTX_MIME_ATACH);
1165         /* load the actual attachment into WC->attachments; no output!!! */
1166         RegisterNamespace("MAIL:MIME:LOADDATA", 0, 0, tmplput_MIME_LoadData, CTX_MIME_ATACH);
1167
1168         /* iterate the WC->attachments; use the above tokens for their contents */
1169         RegisterIterator("MSG:ATTACHNAMES", 0, NULL, iterate_get_registered_Attachments, 
1170                          NULL, NULL, CTX_MIME_ATACH, CTX_NONE, IT_NOFLAG);
1171
1172         /* mime renderers translate an attachment into webcit viewable html text */
1173         RegisterMimeRenderer(HKEY("message/rfc822"), render_MAIL);
1174         RegisterMimeRenderer(HKEY("text/x-vcard"), render_MIME_VCard);
1175         RegisterMimeRenderer(HKEY("text/vcard"), render_MIME_VCard);
1176         RegisterMimeRenderer(HKEY("text/calendar"), render_MIME_ICS);
1177         RegisterMimeRenderer(HKEY("application/ics"), render_MIME_ICS);
1178         RegisterMimeRenderer(HKEY("text/x-citadel-variformat"), render_MAIL_variformat);
1179         RegisterMimeRenderer(HKEY("text/plain"), render_MAIL_text_plain);
1180         RegisterMimeRenderer(HKEY("text"), render_MAIL_text_plain);
1181         RegisterMimeRenderer(HKEY("text/html"), render_MAIL_html);
1182         RegisterMimeRenderer(HKEY(""), render_MAIL_UNKNOWN);
1183
1184         /* these headers are citserver replies to MSG4 and friends. one evaluator for each */
1185         RegisterMsgHdr(HKEY("nhdr"), examine_nhdr, 0);
1186         RegisterMsgHdr(HKEY("type"), examine_type, 0);
1187         RegisterMsgHdr(HKEY("from"), examine_from, 0);
1188         RegisterMsgHdr(HKEY("subj"), examine_subj, 0);
1189         RegisterMsgHdr(HKEY("msgn"), examine_msgn, 0);
1190         RegisterMsgHdr(HKEY("wefw"), examine_wefw, 0);
1191         RegisterMsgHdr(HKEY("cccc"), examine_cccc, 0);
1192         RegisterMsgHdr(HKEY("hnod"), examine_hnod, 0);
1193         RegisterMsgHdr(HKEY("room"), examine_room, 0);
1194         RegisterMsgHdr(HKEY("rfca"), examine_rfca, 0);
1195         RegisterMsgHdr(HKEY("node"), examine_node, 0);
1196         RegisterMsgHdr(HKEY("rcpt"), examine_rcpt, 0);
1197         RegisterMsgHdr(HKEY("time"), examine_time, 0);
1198         RegisterMsgHdr(HKEY("part"), examine_mime_part, 0);
1199         RegisterMsgHdr(HKEY("text"), examine_text, 1);
1200         /* these are the content-type headers we get infront of a message; put it into the same hash since it doesn't clash. */
1201         RegisterMsgHdr(HKEY("X-Citadel-MSG4-Partnum"), examine_msg4_partnum, 0);
1202         RegisterMsgHdr(HKEY("Content-type"), examine_content_type, 0);
1203         RegisterMsgHdr(HKEY("Content-length"), examine_content_lengh, 0);
1204         RegisterMsgHdr(HKEY("Content-transfer-encoding"), examine_content_encoding, 0); /* do we care? */
1205         RegisterMsgHdr(HKEY("charset"), examine_charset, 0);
1206
1207         /* Don't care about these... */
1208         RegisterMsgHdr(HKEY("pref"), examine_pref, 0);
1209         RegisterMsgHdr(HKEY("suff"), examine_suff, 0);
1210         RegisterMsgHdr(HKEY("path"), examine_path, 0);
1211 }