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