7 inline void CheckConvertBufs(struct wcsession *WCC)
9 if (WCC->ConvertBuf1 == NULL)
10 WCC->ConvertBuf1 = NewStrBuf();
11 if (WCC->ConvertBuf2 == NULL)
12 WCC->ConvertBuf2 = NewStrBuf();
16 * message index functions
20 void DestroyMimeParts(wc_mime_attachment *Mime)
22 FreeStrBuf(&Mime->Name);
23 FreeStrBuf(&Mime->FileName);
24 FreeStrBuf(&Mime->PartNum);
25 FreeStrBuf(&Mime->Disposition);
26 FreeStrBuf(&Mime->ContentType);
27 FreeStrBuf(&Mime->Charset);
28 FreeStrBuf(&Mime->Data);
31 void DestroyMime(void *vMime)
33 wc_mime_attachment *Mime = (wc_mime_attachment*)vMime;
34 DestroyMimeParts(Mime);
38 void DestroyMessageSummary(void *vMsg)
40 message_summary *Msg = (message_summary*) vMsg;
42 FreeStrBuf(&Msg->from);
44 FreeStrBuf(&Msg->subj);
45 FreeStrBuf(&Msg->reply_inreplyto);
46 FreeStrBuf(&Msg->reply_references);
47 FreeStrBuf(&Msg->cccc);
48 FreeStrBuf(&Msg->ReplyTo);
49 FreeStrBuf(&Msg->hnod);
50 FreeStrBuf(&Msg->AllRcpt);
51 FreeStrBuf(&Msg->Room);
52 FreeStrBuf(&Msg->Rfca);
53 FreeStrBuf(&Msg->OtherNode);
55 DeleteHash(&Msg->Attachments); /* list of Attachments */
56 DeleteHash(&Msg->Submessages);
57 DeleteHash(&Msg->AttachLinks);
58 DeleteHash(&Msg->AllAttach);
64 void RegisterMsgHdr(const char *HeaderName, long HdrNLen, ExamineMsgHeaderFunc evaluator, int type)
67 ev = (headereval*) malloc(sizeof(headereval));
68 ev->evaluator = evaluator;
70 Put(MsgHeaderHandler, HeaderName, HdrNLen, ev, NULL);
73 void RegisterMimeRenderer(const char *HeaderName, long HdrNLen,
74 RenderMimeFunc MimeRenderer,
78 RenderMimeFuncStruct *f;
80 f = (RenderMimeFuncStruct*) malloc(sizeof(RenderMimeFuncStruct));
82 Put(MimeRenderHandler, HeaderName, HdrNLen, f, NULL);
84 RegisterEmbeddableMimeType(HeaderName, HdrNLen, 10000 - Priority);
87 /*----------------------------------------------------------------------------*/
90 * comparator for two longs in descending order.
92 int longcmp_r(const void *s1, const void *s2) {
96 l1 = *(long *)GetSearchPayload(s1);
97 l2 = *(long *)GetSearchPayload(s2);
99 if (l1 > l2) return(-1);
100 if (l1 < l2) return(+1);
105 * comparator for longs; descending order.
107 int qlongcmp_r(const void *s1, const void *s2) {
111 if (l1 > l2) return(-1);
112 if (l1 < l2) return(+1);
118 * comparator for message summary structs by ascending subject.
120 int summcmp_subj(const void *s1, const void *s2) {
121 message_summary *summ1;
122 message_summary *summ2;
124 summ1 = (message_summary *)GetSearchPayload(s1);
125 summ2 = (message_summary *)GetSearchPayload(s2);
126 return strcasecmp(ChrPtr(summ1->subj), ChrPtr(summ2->subj));
130 * comparator for message summary structs by descending subject.
132 int summcmp_rsubj(const void *s1, const void *s2) {
133 message_summary *summ1;
134 message_summary *summ2;
136 summ1 = (message_summary *)GetSearchPayload(s1);
137 summ2 = (message_summary *)GetSearchPayload(s2);
138 return strcasecmp(ChrPtr(summ2->subj), ChrPtr(summ1->subj));
141 * comparator for message summary structs by descending subject.
143 int groupchange_subj(const void *s1, const void *s2) {
144 message_summary *summ1;
145 message_summary *summ2;
147 summ1 = (message_summary *)s1;
148 summ2 = (message_summary *)s2;
149 return ChrPtr(summ2->subj)[0] != ChrPtr(summ1->subj)[0];
153 * comparator for message summary structs by ascending sender.
155 int summcmp_sender(const void *s1, const void *s2) {
156 message_summary *summ1;
157 message_summary *summ2;
159 summ1 = (message_summary *)GetSearchPayload(s1);
160 summ2 = (message_summary *)GetSearchPayload(s2);
161 return strcasecmp(ChrPtr(summ1->from), ChrPtr(summ2->from));
165 * comparator for message summary structs by descending sender.
167 int summcmp_rsender(const void *s1, const void *s2) {
168 message_summary *summ1;
169 message_summary *summ2;
171 summ1 = (message_summary *)GetSearchPayload(s1);
172 summ2 = (message_summary *)GetSearchPayload(s2);
173 return strcasecmp(ChrPtr(summ2->from), ChrPtr(summ1->from));
176 * comparator for message summary structs by descending sender.
178 int groupchange_sender(const void *s1, const void *s2) {
179 message_summary *summ1;
180 message_summary *summ2;
182 summ1 = (message_summary *)s1;
183 summ2 = (message_summary *)s2;
184 return strcasecmp(ChrPtr(summ2->from), ChrPtr(summ1->from)) != 0;
189 * comparator for message summary structs by ascending date.
191 int summcmp_date(const void *s1, const void *s2) {
192 message_summary *summ1;
193 message_summary *summ2;
195 summ1 = (message_summary *)GetSearchPayload(s1);
196 summ2 = (message_summary *)GetSearchPayload(s2);
198 if (summ1->date < summ2->date) return -1;
199 else if (summ1->date > summ2->date) return +1;
204 * comparator for message summary structs by descending date.
206 int summcmp_rdate(const void *s1, const void *s2) {
207 message_summary *summ1;
208 message_summary *summ2;
210 summ1 = (message_summary *)GetSearchPayload(s1);
211 summ2 = (message_summary *)GetSearchPayload(s2);
213 if (summ1->date < summ2->date) return +1;
214 else if (summ1->date > summ2->date) return -1;
219 * comparator for message summary structs by descending date.
221 const long DAYSECONDS = 24 * 60 * 60;
222 int groupchange_date(const void *s1, const void *s2) {
223 message_summary *summ1;
224 message_summary *summ2;
226 summ1 = (message_summary *)s1;
227 summ2 = (message_summary *)s2;
229 return (summ1->date % DAYSECONDS) != (summ2->date %DAYSECONDS);
233 /*----------------------------------------------------------------------------*/
234 /* Don't wanna know... or? */
235 void examine_pref(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset) {return;}
236 void examine_suff(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset) {return;}
237 void examine_path(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset) {return;}
238 void examine_content_encoding(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
240 /* TODO: do we care? */
243 void examine_nhdr(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
246 if (!strncasecmp(ChrPtr(HdrLine), "yes", 8))
249 int Conditional_ANONYMOUS_MESSAGE(StrBuf *Target, WCTemplputParams *TP)
251 message_summary *Msg = (message_summary*) CTX;
252 return Msg->nhdr != 0;
255 void examine_type(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
257 Msg->format_type = StrToi(HdrLine);
261 void examine_from(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
265 CheckConvertBufs(WCC);
266 FreeStrBuf(&Msg->from);
267 Msg->from = NewStrBufPlain(NULL, StrLength(HdrLine));
268 StrBuf_RFC822_2_Utf8(Msg->from,
275 void tmplput_MAIL_SUMM_FROM(StrBuf *Target, WCTemplputParams *TP)
277 message_summary *Msg = (message_summary*) CTX;
278 StrBufAppendTemplate(Target, TP, Msg->from, 0);
281 void examine_subj(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
285 CheckConvertBufs(WCC);
286 FreeStrBuf(&Msg->subj);
287 Msg->subj = NewStrBufPlain(NULL, StrLength(HdrLine));
288 StrBuf_RFC822_2_Utf8(Msg->subj,
295 void tmplput_MAIL_SUMM_SUBJECT(StrBuf *Target, WCTemplputParams *TP)
297 message_summary *Msg = (message_summary*) CTX;
299 if (TP->Tokens->nParameters == 4)
304 GetTemplateTokenString(Target, TP, 3, &pch, &len);
306 (strstr(ChrPtr(Msg->subj), pch) == NULL))
308 GetTemplateTokenString(Target, TP, 2, &pch, &len);
309 StrBufAppendBufPlain(Target, pch, len, 0);
312 StrBufAppendTemplate(Target, TP, Msg->subj, 0);
314 int Conditional_MAIL_SUMM_SUBJECT(StrBuf *Target, WCTemplputParams *TP)
316 message_summary *Msg = (message_summary*) CTX;
319 return StrLength(Msg->subj) > 0;
323 void examine_msgn(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
327 CheckConvertBufs(WCC);
328 FreeStrBuf(&Msg->reply_inreplyto);
329 Msg->reply_inreplyto = NewStrBufPlain(NULL, StrLength(HdrLine));
330 StrBuf_RFC822_2_Utf8(Msg->reply_inreplyto,
337 void tmplput_MAIL_SUMM_INREPLYTO(StrBuf *Target, WCTemplputParams *TP)
339 message_summary *Msg = (message_summary*) CTX;
340 StrBufAppendTemplate(Target, TP, Msg->reply_inreplyto, 0);
343 int Conditional_MAIL_SUMM_UNREAD(StrBuf *Target, WCTemplputParams *TP)
345 message_summary *Msg = (message_summary*) CTX;
346 return (Msg->Flags & MSGFLAG_READ) != 0;
349 void examine_wefw(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
353 CheckConvertBufs(WCC);
354 FreeStrBuf(&Msg->reply_references);
355 Msg->reply_references = NewStrBufPlain(NULL, StrLength(HdrLine));
356 StrBuf_RFC822_2_Utf8(Msg->reply_references,
363 void tmplput_MAIL_SUMM_REFIDS(StrBuf *Target, WCTemplputParams *TP)
365 message_summary *Msg = (message_summary*) CTX;
366 StrBufAppendTemplate(Target, TP, Msg->reply_references, 0);
369 void examine_replyto(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
373 CheckConvertBufs(WCC);
374 FreeStrBuf(&Msg->ReplyTo);
375 Msg->ReplyTo = NewStrBufPlain(NULL, StrLength(HdrLine));
376 StrBuf_RFC822_2_Utf8(Msg->ReplyTo,
382 if (Msg->AllRcpt == NULL)
383 Msg->AllRcpt = NewStrBufPlain(NULL, StrLength(HdrLine));
384 if (StrLength(Msg->AllRcpt) > 0) {
385 StrBufAppendBufPlain(Msg->AllRcpt, HKEY(", "), 0);
387 StrBufAppendBuf(Msg->AllRcpt, Msg->ReplyTo, 0);
389 void tmplput_MAIL_SUMM_REPLYTO(StrBuf *Target, WCTemplputParams *TP)
391 message_summary *Msg = (message_summary*) CTX;
392 StrBufAppendTemplate(Target, TP, Msg->ReplyTo, 0);
395 void examine_cccc(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
399 CheckConvertBufs(WCC);
400 FreeStrBuf(&Msg->cccc);
401 Msg->cccc = NewStrBufPlain(NULL, StrLength(HdrLine));
402 StrBuf_RFC822_2_Utf8(Msg->cccc,
408 if (Msg->AllRcpt == NULL)
409 Msg->AllRcpt = NewStrBufPlain(NULL, StrLength(HdrLine));
410 if (StrLength(Msg->AllRcpt) > 0) {
411 StrBufAppendBufPlain(Msg->AllRcpt, HKEY(", "), 0);
413 StrBufAppendBuf(Msg->AllRcpt, Msg->cccc, 0);
415 void tmplput_MAIL_SUMM_CCCC(StrBuf *Target, WCTemplputParams *TP)
417 message_summary *Msg = (message_summary*) CTX;
418 StrBufAppendTemplate(Target, TP, Msg->cccc, 0);
422 void examine_room(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
424 if ((StrLength(HdrLine) > 0) &&
425 (strcasecmp(ChrPtr(HdrLine), ChrPtr(WC->CurRoom.name)))) {
426 FreeStrBuf(&Msg->Room);
427 Msg->Room = NewStrBufDup(HdrLine);
430 void tmplput_MAIL_SUMM_ORGROOM(StrBuf *Target, WCTemplputParams *TP)
432 message_summary *Msg = (message_summary*) CTX;
433 StrBufAppendTemplate(Target, TP, Msg->Room, 0);
437 void examine_rfca(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
439 FreeStrBuf(&Msg->Rfca);
440 Msg->Rfca = NewStrBufDup(HdrLine);
442 void tmplput_MAIL_SUMM_RFCA(StrBuf *Target, WCTemplputParams *TP)
444 message_summary *Msg = (message_summary*) CTX;
445 StrBufAppendTemplate(Target, TP, Msg->Rfca, 0);
447 int Conditional_MAIL_SUMM_RFCA(StrBuf *Target, WCTemplputParams *TP)
449 message_summary *Msg = (message_summary*) CTX;
450 return StrLength(Msg->Rfca) > 0;
452 int Conditional_MAIL_SUMM_CCCC(StrBuf *Target, WCTemplputParams *TP)
454 message_summary *Msg = (message_summary*) CTX;
455 return StrLength(Msg->cccc) > 0;
457 int Conditional_MAIL_SUMM_REPLYTO(StrBuf *Target, WCTemplputParams *TP)
459 message_summary *Msg = (message_summary*) CTX;
460 return StrLength(Msg->ReplyTo) > 0;
463 void examine_node(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
467 if ( (StrLength(HdrLine) > 0) &&
468 ((WC->CurRoom.QRFlags & QR_NETWORK)
469 || ((strcasecmp(ChrPtr(HdrLine), ChrPtr(WCC->serv_info->serv_nodename))
470 && (strcasecmp(ChrPtr(HdrLine), ChrPtr(WCC->serv_info->serv_fqdn))))))) {
471 FreeStrBuf(&Msg->OtherNode);
472 Msg->OtherNode = NewStrBufDup(HdrLine);
475 void tmplput_MAIL_SUMM_OTHERNODE(StrBuf *Target, WCTemplputParams *TP)
477 message_summary *Msg = (message_summary*) CTX;
478 StrBufAppendTemplate(Target, TP, Msg->OtherNode, 0);
480 int Conditional_MAIL_SUMM_OTHERNODE(StrBuf *Target, WCTemplputParams *TP)
482 message_summary *Msg = (message_summary*) CTX;
483 return StrLength(Msg->OtherNode) > 0;
487 void examine_rcpt(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
491 CheckConvertBufs(WCC);
492 FreeStrBuf(&Msg->to);
493 Msg->to = NewStrBufPlain(NULL, StrLength(HdrLine));
494 StrBuf_RFC822_2_Utf8(Msg->to,
500 if (Msg->AllRcpt == NULL)
501 Msg->AllRcpt = NewStrBufPlain(NULL, StrLength(HdrLine));
502 if (StrLength(Msg->AllRcpt) > 0) {
503 StrBufAppendBufPlain(Msg->AllRcpt, HKEY(", "), 0);
505 StrBufAppendBuf(Msg->AllRcpt, Msg->to, 0);
507 void tmplput_MAIL_SUMM_TO(StrBuf *Target, WCTemplputParams *TP)
509 message_summary *Msg = (message_summary*) CTX;
510 StrBufAppendTemplate(Target, TP, Msg->to, 0);
512 int Conditional_MAIL_SUMM_TO(StrBuf *Target, WCTemplputParams *TP)
514 message_summary *Msg = (message_summary*) CTX;
515 return StrLength(Msg->to) != 0;
517 int Conditional_MAIL_SUMM_SUBJ(StrBuf *Target, WCTemplputParams *TP)
519 message_summary *Msg = (message_summary*) CTX;
520 return StrLength(Msg->subj) != 0;
522 void tmplput_MAIL_SUMM_ALLRCPT(StrBuf *Target, WCTemplputParams *TP)
524 message_summary *Msg = (message_summary*) CTX;
525 StrBufAppendTemplate(Target, TP, Msg->AllRcpt, 0);
530 void tmplput_SUMM_COUNT(StrBuf *Target, WCTemplputParams *TP)
532 StrBufAppendPrintf(Target, "%d", GetCount( WC->summ));
535 HashList *iterate_get_mailsumm_All(StrBuf *Target, WCTemplputParams *TP)
539 void examine_time(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
541 Msg->date = StrTol(HdrLine);
544 void tmplput_MAIL_SUMM_DATE_BRIEF(StrBuf *Target, WCTemplputParams *TP)
547 message_summary *Msg = (message_summary*) CTX;
548 webcit_fmt_date(datebuf, 64, Msg->date, DATEFMT_BRIEF);
549 StrBufAppendBufPlain(Target, datebuf, -1, 0);
552 void tmplput_MAIL_SUMM_EUID(StrBuf *Target, WCTemplputParams *TP)
554 message_summary *Msg = (message_summary*) CTX;
555 StrBufAppendTemplate(Target, TP, Msg->euid, 0);
558 void tmplput_MAIL_SUMM_DATE_FULL(StrBuf *Target, WCTemplputParams *TP)
561 message_summary *Msg = (message_summary*) CTX;
562 webcit_fmt_date(datebuf, 64, Msg->date, DATEFMT_FULL);
563 StrBufAppendBufPlain(Target, datebuf, -1, 0);
565 void tmplput_MAIL_SUMM_DATE_NO(StrBuf *Target, WCTemplputParams *TP)
567 message_summary *Msg = (message_summary*) CTX;
568 StrBufAppendPrintf(Target, "%ld", Msg->date, 0);
573 void render_MAIL(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCharset)
575 const StrBuf *TemplateMime;
577 if (Mime->Data == NULL)
578 Mime->Data = NewStrBufPlain(NULL, Mime->length);
580 FlushStrBuf(Mime->Data);
581 read_message(Mime->Data, HKEY("view_submessage"), Mime->msgnum, Mime->PartNum, &TemplateMime);
583 if ( (!IsEmptyStr(mime_submessages)) && (!section[0]) ) {
584 for (i=0; i<num_tokens(mime_submessages, '|'); ++i) {
585 extract_token(buf, mime_submessages, i, '|', sizeof buf);
586 / ** use printable_view to suppress buttons * /
587 wc_printf("<blockquote>");
588 read_message(Mime->msgnum, 1, ChrPtr(Mime->Section));
589 wc_printf("</blockquote>");
595 void render_MIME_VCard(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCharset)
598 if (StrLength(Mime->Data) == 0)
600 if (StrLength(Mime->Data) > 0) {
603 /** If it's my vCard I can edit it */
604 if ( (!strcasecmp(ChrPtr(WCC->CurRoom.name), USERCONFIGROOM))
605 || (!strcasecmp(&(ChrPtr(WCC->CurRoom.name)[11]), USERCONFIGROOM))
606 || (WC->CurRoom.view == VIEW_ADDRESSBOOK)
608 StrBufAppendPrintf(Buf, "<a href=\"edit_vcard?msgnum=%ld?partnum=%s\">",
609 Mime->msgnum, ChrPtr(Mime->PartNum));
610 StrBufAppendPrintf(Buf, "[%s]</a>", _("edit"));
613 /* In all cases, display the full card */
614 display_vcard(Buf, Mime, 0, 1, NULL, -1);
615 FreeStrBuf(&Mime->Data);
621 void render_MIME_VNote(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCharset)
623 if (StrLength(Mime->Data) == 0)
625 if (StrLength(Mime->Data) > 0) {
631 vcard = SmashStrBuf(&Mime->Data);
632 v = vnote_new_from_str(vcard);
637 memset(&TP, 0, sizeof(WCTemplputParams));
638 TP.Filter.ContextType = CTX_VNOTE;
640 DoTemplate(HKEY("mail_vnoteitem"),
647 if (Mime->Data == NULL)
648 Mime->Data = NewStrBuf();
650 FlushStrBuf(Mime->Data);
655 void render_MIME_ICS(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCharset)
657 if (StrLength(Mime->Data) == 0) {
660 if (StrLength(Mime->Data) > 0) {
661 cal_process_attachment(Mime);
667 void examine_mime_part(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
669 const char *Ptr = NULL;
670 wc_mime_attachment *Mime;
674 CheckConvertBufs(WCC);
675 Mime = (wc_mime_attachment*) malloc(sizeof(wc_mime_attachment));
676 memset(Mime, 0, sizeof(wc_mime_attachment));
677 Mime->msgnum = Msg->msgnum;
680 Mime->Name = NewStrBuf();
681 StrBufExtract_NextToken(Buf, HdrLine, &Ptr, '|');
682 StrBuf_RFC822_2_Utf8(Mime->Name,
688 StrBufTrim(Mime->Name);
690 StrBufExtract_NextToken(Buf, HdrLine, &Ptr, '|');
691 Mime->FileName = NewStrBuf();
692 StrBuf_RFC822_2_Utf8(Mime->FileName,
698 StrBufTrim(Mime->FileName);
700 Mime->PartNum = NewStrBuf();
701 StrBufExtract_NextToken(Mime->PartNum, HdrLine, &Ptr, '|');
702 StrBufTrim(Mime->PartNum);
703 if (strchr(ChrPtr(Mime->PartNum), '.') != NULL)
708 Mime->Disposition = NewStrBuf();
709 StrBufExtract_NextToken(Mime->Disposition, HdrLine, &Ptr, '|');
711 Mime->ContentType = NewStrBuf();
712 StrBufExtract_NextToken(Mime->ContentType, HdrLine, &Ptr, '|');
713 StrBufTrim(Mime->ContentType);
714 StrBufLowerCase(Mime->ContentType);
715 if (!strcmp(ChrPtr(Mime->ContentType), "application/octet-stream")) {
716 StrBufPlain(Mime->ContentType,
717 GuessMimeByFilename(SKEY(Mime->FileName)), -1);
720 Mime->length = StrBufExtractNext_int(HdrLine, &Ptr, '|');
722 StrBufSkip_NTokenS(HdrLine, &Ptr, '|', 1); /* cbid?? */
724 Mime->Charset = NewStrBuf();
725 StrBufExtract_NextToken(Mime->Charset, HdrLine, &Ptr, '|');
728 if ( (StrLength(Mime->FileName) == 0) && (StrLength(Mime->Name) > 0) ) {
729 StrBufAppendBuf(Mime->FileName, Mime->Name, 0);
732 if (StrLength(Msg->PartNum) > 0) {
734 StrBufPrintf(Buf, "%s.%s", ChrPtr(Msg->PartNum), ChrPtr(Mime->PartNum));
740 if (Msg->AllAttach == NULL)
741 Msg->AllAttach = NewHash(1,NULL);
742 Put(Msg->AllAttach, SKEY(Mime->PartNum), Mime, DestroyMime);
747 void evaluate_mime_part(message_summary *Msg, wc_mime_attachment *Mime)
751 /* just print the root-node */
752 if ((Mime->level >= 1) &&
753 GetHash(MimeRenderHandler, SKEY(Mime->ContentType), &vMimeRenderer) &&
754 vMimeRenderer != NULL)
756 Mime->Renderer = (RenderMimeFuncStruct*) vMimeRenderer;
757 if (Msg->Submessages == NULL)
758 Msg->Submessages = NewHash(1,NULL);
759 Put(Msg->Submessages, SKEY(Mime->PartNum), Mime, reference_free_handler);
761 else if ((Mime->level >= 1) &&
762 (!strcasecmp(ChrPtr(Mime->Disposition), "inline"))
763 && (!strncasecmp(ChrPtr(Mime->ContentType), "image/", 6)) ){
764 if (Msg->AttachLinks == NULL)
765 Msg->AttachLinks = NewHash(1,NULL);
766 Put(Msg->AttachLinks, SKEY(Mime->PartNum), Mime, reference_free_handler);
768 else if ((Mime->level >= 1) &&
769 (StrLength(Mime->ContentType) > 0) &&
770 ( (!strcasecmp(ChrPtr(Mime->Disposition), "attachment"))
771 || (!strcasecmp(ChrPtr(Mime->Disposition), "inline"))
772 || (!strcasecmp(ChrPtr(Mime->Disposition), ""))))
774 if (Msg->AttachLinks == NULL)
775 Msg->AttachLinks = NewHash(1,NULL);
776 Put(Msg->AttachLinks, SKEY(Mime->PartNum), Mime, reference_free_handler);
777 if ((strcasecmp(ChrPtr(Mime->ContentType), "application/octet-stream") == 0) &&
778 (StrLength(Mime->FileName) > 0)) {
779 FlushStrBuf(Mime->ContentType);
780 StrBufAppendBufPlain(Mime->ContentType,
781 GuessMimeByFilename(SKEY(Mime->FileName)),
787 void tmplput_MAIL_SUMM_NATTACH(StrBuf *Target, WCTemplputParams *TP)
789 message_summary *Msg = (message_summary*) CTX;
790 StrBufAppendPrintf(Target, "%ld", GetCount(Msg->Attachments));
794 void examine_hnod(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
798 CheckConvertBufs(WCC);
799 FreeStrBuf(&Msg->hnod);
800 Msg->hnod = NewStrBufPlain(NULL, StrLength(HdrLine));
801 StrBuf_RFC822_2_Utf8(Msg->hnod,
808 void tmplput_MAIL_SUMM_H_NODE(StrBuf *Target, WCTemplputParams *TP)
810 message_summary *Msg = (message_summary*) CTX;
811 StrBufAppendTemplate(Target, TP, Msg->hnod, 0);
813 int Conditional_MAIL_SUMM_H_NODE(StrBuf *Target, WCTemplputParams *TP)
815 message_summary *Msg = (message_summary*) CTX;
816 return StrLength(Msg->hnod) > 0;
821 void examine_text(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
823 if (Msg->MsgBody->Data == NULL)
824 Msg->MsgBody->Data = NewStrBufPlain(NULL, SIZ);
826 FlushStrBuf(Msg->MsgBody->Data);
829 void examine_msg4_partnum(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
831 Msg->MsgBody->PartNum = NewStrBufDup(HdrLine);
832 StrBufTrim(Msg->MsgBody->PartNum);
835 void examine_content_lengh(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
837 Msg->MsgBody->length = StrTol(HdrLine);
838 Msg->MsgBody->size_known = 1;
841 void examine_content_type(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
851 Msg->MsgBody->ContentType = NewStrBufDup(HdrLine);
852 sem = strchr(ChrPtr(HdrLine), ';');
855 Token = NewStrBufPlain(NULL, StrLength(HdrLine));
856 Value = NewStrBufPlain(NULL, StrLength(HdrLine));
857 len = sem - ChrPtr(HdrLine);
858 StrBufCutAt(Msg->MsgBody->ContentType, len, NULL);
859 while (sem != NULL) {
860 while (isspace(*(sem + 1)))
862 StrBufCutLeft(HdrLine, sem - ChrPtr(HdrLine));
863 sem = strchr(ChrPtr(HdrLine), ';');
865 len = sem - ChrPtr(HdrLine);
867 len = StrLength(HdrLine);
870 StrBufAppendBufPlain(Token, ChrPtr(HdrLine), len, 0);
871 eq = strchr(ChrPtr(Token), '=');
873 len = eq - ChrPtr(Token);
874 StrBufAppendBufPlain(Value, eq + 1, StrLength(Token) - len - 1, 0);
875 StrBufCutAt(Token, len, NULL);
880 if (GetHash(MsgHeaderHandler, SKEY(Token), &vHdr) &&
882 Hdr = (headereval*)vHdr;
883 Hdr->evaluator(Msg, Value, FoundCharset);
885 else syslog(1, "don't know how to handle content type sub-header[%s]\n", ChrPtr(Token));
892 void tmplput_MAIL_SUMM_N(StrBuf *Target, WCTemplputParams *TP)
894 message_summary *Msg = (message_summary*) CTX;
895 StrBufAppendPrintf(Target, "%ld", Msg->msgnum);
899 void tmplput_MAIL_SUMM_PERMALINK(StrBuf *Target, WCTemplputParams *TP)
901 message_summary *Msg = (message_summary*) CTX;
902 char perma_link[1024];
904 strcpy(perma_link, "/readfwd?go=");
905 urlesc(&perma_link[12], sizeof(perma_link) - 12, (char *)ChrPtr(WC->CurRoom.name) );
906 sprintf(&perma_link[strlen(perma_link)], "?start_reading_at=%ld#%ld", Msg->msgnum, Msg->msgnum);
907 StrBufAppendPrintf(Target, "%s", perma_link);
911 int Conditional_MAIL_MIME_ALL(StrBuf *Target, WCTemplputParams *TP)
913 message_summary *Msg = (message_summary*) CTX;
914 return GetCount(Msg->Attachments) > 0;
917 int Conditional_MAIL_MIME_SUBMESSAGES(StrBuf *Target, WCTemplputParams *TP)
919 message_summary *Msg = (message_summary*) CTX;
920 return GetCount(Msg->Submessages) > 0;
923 int Conditional_MAIL_MIME_ATTACHLINKS(StrBuf *Target, WCTemplputParams *TP)
925 message_summary *Msg = (message_summary*) CTX;
926 return GetCount(Msg->AttachLinks) > 0;
929 int Conditional_MAIL_MIME_ATTACH(StrBuf *Target, WCTemplputParams *TP)
931 message_summary *Msg = (message_summary*) CTX;
932 return GetCount(Msg->AllAttach) > 0;
935 void tmplput_QUOTED_MAIL_BODY(StrBuf *Target, WCTemplputParams *TP)
941 MsgNum = LBstr(TKEY(0));
943 read_message(Buf, HKEY("view_message_replyquote"), MsgNum, NULL, &Mime);
944 StrBufAppendTemplate(Target, TP, Buf, 1);
948 void tmplput_EDIT_MAIL_BODY(StrBuf *Target, WCTemplputParams *TP)
954 MsgNum = LBstr(TKEY(0));
956 read_message(Buf, HKEY("view_message_edit"), MsgNum, NULL, &Mime);
957 StrBufAppendTemplate(Target, TP, Buf, 1);
961 void tmplput_EDIT_WIKI_BODY(StrBuf *Target, WCTemplputParams *TP)
967 /* Insert the existing content of the wiki page into the editor. But we only want
968 * to do this the first time -- if the user is uploading an attachment we don't want
971 if (!havebstr("attach_button")) {
972 char *wikipage = strdup(bstr("page"));
973 str_wiki_index(wikipage);
974 msgnum = locate_message_by_uid(wikipage);
978 read_message(Buf, HKEY("view_message_wikiedit"), msgnum, NULL, &Mime);
979 StrBufAppendTemplate(Target, TP, Buf, 1);
985 void tmplput_MAIL_BODY(StrBuf *Target, WCTemplputParams *TP)
987 message_summary *Msg = (message_summary*) CTX;
988 StrBufAppendTemplate(Target, TP, Msg->MsgBody->Data, 0);
992 void render_MAIL_variformat(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCharset)
994 /* Messages in legacy Citadel variformat get handled thusly... */
995 StrBuf *Target = NewStrBufPlain(NULL, StrLength(Mime->Data));
996 FmOut(Target, "JUSTIFY", Mime->Data);
997 FreeStrBuf(&Mime->Data);
1001 void render_MAIL_text_plain(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCharset)
1003 const char *ptr, *pte;
1004 const char *BufPtr = NULL;
1018 iconv_t ic = (iconv_t)(-1) ;
1021 if ((StrLength(Mime->Data) == 0) && (Mime->length > 0)) {
1022 FreeStrBuf(&Mime->Data);
1028 if (StrLength(Mime->Charset) != 0)
1030 else if (StrLength(FoundCharset) > 0)
1032 else if (StrLength(WC->DefaultCharset) > 0)
1033 cs = WC->DefaultCharset;
1037 else if (!strcasecmp(ChrPtr(cs), "utf-8")) {
1040 else if (!strcasecmp(ChrPtr(cs), "us-ascii")) {
1044 ctdl_iconv_open("UTF-8", ChrPtr(cs), &ic);
1045 if (ic == (iconv_t)(-1) ) {
1046 syslog(5, "%s:%d iconv_open(UTF-8, %s) failed: %s\n",
1047 __FILE__, __LINE__, ChrPtr(Mime->Charset), strerror(errno));
1052 Line = NewStrBufPlain(NULL, SIZ);
1053 Line1 = NewStrBufPlain(NULL, SIZ);
1054 Line2 = NewStrBufPlain(NULL, SIZ);
1055 Target = NewStrBufPlain(NULL, StrLength(Mime->Data));
1058 if (StrLength(Mime->Data) > 0)
1061 StrBufSipLine(Line, Mime->Data, &BufPtr);
1065 len = StrLength(Line);
1068 while ((ptr < pte) &&
1077 if (i > 0) StrBufCutLeft(Line, i);
1079 if (StrLength(Line) == 0) {
1082 StrBufAppendBufPlain(Target, HKEY("<tt></tt><br>\n"), 0);
1088 for (i = bn; i < bq; i++)
1089 StrBufAppendBufPlain(Target, HKEY("<blockquote>"), 0);
1090 for (i = bq; i < bn; i++)
1091 StrBufAppendBufPlain(Target, HKEY("</blockquote>"), 0);
1094 StrBufConvert(Line, Line1, &ic);
1097 StrBufAppendBufPlain(Target, HKEY("<tt>"), 0);
1098 UrlizeText(Line1, Line, Line2);
1100 StrEscAppend(Target, Line1, NULL, 0, 0);
1101 StrBufAppendBufPlain(Target, HKEY("</tt><br>\n"), 0);
1105 while ((BufPtr != StrBufNOTNULL) &&
1108 if (nEmptyLines > 0)
1109 StrBufCutRight(Target, nEmptyLines * (sizeof ("<tt></tt><br>\n") - 1));
1110 for (i = 0; i < bn; i++)
1111 StrBufAppendBufPlain(Target, HKEY("</blockquote>"), 0);
1113 StrBufAppendBufPlain(Target, HKEY("</i><br>"), 0);
1115 if (ic != (iconv_t)(-1) ) {
1120 FreeStrBuf(&Mime->Data);
1121 Mime->Data = Target;
1122 FlushStrBuf(Mime->ContentType);
1123 StrBufAppendBufPlain(Mime->ContentType, HKEY("text/html"), 0);
1124 FlushStrBuf(Mime->Charset);
1125 StrBufAppendBufPlain(Mime->Charset, HKEY("UTF-8"), 0);
1131 void render_MAIL_html(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCharset)
1135 if (StrLength(Mime->Data) == 0)
1138 Buf = NewStrBufPlain(NULL, StrLength(Mime->Data));
1140 /* HTML is fun, but we've got to strip it first */
1141 output_html(ChrPtr(Mime->Charset),
1142 (WC->CurRoom.view == VIEW_WIKI ? 1 : 0),
1145 FreeStrBuf(&Mime->Data);
1149 void render_MAIL_UNKNOWN(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCharset)
1151 /* Unknown weirdness */
1152 FlushStrBuf(Mime->Data);
1153 StrBufAppendBufPlain(Mime->Data, _("I don't know how to display "), -1, 0);
1154 StrBufAppendBuf(Mime->Data, Mime->ContentType, 0);
1155 StrBufAppendBufPlain(Mime->Data, HKEY("<br>\n"), 0);
1159 HashList *iterate_get_mime_All(StrBuf *Target, WCTemplputParams *TP)
1161 message_summary *Msg = (message_summary*) CTX;
1162 return Msg->Attachments;
1164 HashList *iterate_get_mime_Submessages(StrBuf *Target, WCTemplputParams *TP)
1166 message_summary *Msg = (message_summary*) CTX;
1167 return Msg->Submessages;
1169 HashList *iterate_get_mime_AttachLinks(StrBuf *Target, WCTemplputParams *TP)
1171 message_summary *Msg = (message_summary*) CTX;
1172 return Msg->AttachLinks;
1174 HashList *iterate_get_mime_Attachments(StrBuf *Target, WCTemplputParams *TP)
1176 message_summary *Msg = (message_summary*) CTX;
1177 return Msg->AllAttach;
1180 void tmplput_MIME_Name(StrBuf *Target, WCTemplputParams *TP)
1182 wc_mime_attachment *mime = (wc_mime_attachment*) CTX;
1183 StrBufAppendTemplate(Target, TP, mime->Name, 0);
1186 void tmplput_MIME_FileName(StrBuf *Target, WCTemplputParams *TP)
1188 wc_mime_attachment *mime = (wc_mime_attachment*) CTX;
1189 StrBufAppendTemplate(Target, TP, mime->FileName, 0);
1192 void tmplput_MIME_PartNum(StrBuf *Target, WCTemplputParams *TP)
1194 wc_mime_attachment *mime = (wc_mime_attachment*) CTX;
1195 StrBufAppendTemplate(Target, TP, mime->PartNum, 0);
1198 void tmplput_MIME_MsgNum(StrBuf *Target, WCTemplputParams *TP)
1200 wc_mime_attachment *mime = (wc_mime_attachment*) CTX;
1201 StrBufAppendPrintf(Target, "%ld", mime->msgnum);
1204 void tmplput_MIME_Disposition(StrBuf *Target, WCTemplputParams *TP)
1206 wc_mime_attachment *mime = (wc_mime_attachment*) CTX;
1207 StrBufAppendTemplate(Target, TP, mime->Disposition, 0);
1210 void tmplput_MIME_ContentType(StrBuf *Target, WCTemplputParams *TP)
1212 wc_mime_attachment *mime = (wc_mime_attachment*) CTX;
1213 StrBufAppendTemplate(Target, TP, mime->ContentType, 0);
1216 void examine_charset(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
1218 Msg->MsgBody->Charset = NewStrBufDup(HdrLine);
1221 void tmplput_MIME_Charset(StrBuf *Target, WCTemplputParams *TP)
1223 wc_mime_attachment *mime = (wc_mime_attachment*) CTX;
1224 StrBufAppendTemplate(Target, TP, mime->Charset, 0);
1227 void tmplput_MIME_Data(StrBuf *Target, WCTemplputParams *TP)
1229 wc_mime_attachment *mime = (wc_mime_attachment*) CTX;
1230 if (mime->Renderer != NULL)
1231 mime->Renderer->f(mime, NULL, NULL);
1232 StrBufAppendTemplate(Target, TP, mime->Data, 0);
1233 /* TODO: check whether we need to load it now? */
1236 void tmplput_MIME_LoadData(StrBuf *Target, WCTemplputParams *TP)
1238 wcsession *WCC = WC;
1239 wc_mime_attachment *mime = (wc_mime_attachment*) CTX;
1240 wc_mime_attachment *att;
1242 if (( (!strcasecmp(ChrPtr(mime->Disposition), "inline"))||
1243 (!strcasecmp(ChrPtr(mime->Disposition), "attachment"))) &&
1244 (strcasecmp(ChrPtr(mime->ContentType), "application/ms-tnef")!=0))
1249 /* steal this mime part... */
1250 att = malloc(sizeof(wc_mime_attachment));
1251 memcpy(att, mime, sizeof(wc_mime_attachment));
1252 memset(mime, 0, sizeof(wc_mime_attachment));
1254 if (att->Data == NULL)
1257 if (WCC->attachments == NULL)
1258 WCC->attachments = NewHash(1, NULL);
1259 /* And add it to the list. */
1260 n = snprintf(N, sizeof N, "%d", GetCount(WCC->attachments) + 1);
1261 Put(WCC->attachments, N, n, att, DestroyMime);
1265 void tmplput_MIME_Length(StrBuf *Target, WCTemplputParams *TP)
1267 wc_mime_attachment *mime = (wc_mime_attachment*) CTX;
1268 StrBufAppendPrintf(Target, "%ld", mime->length);
1271 HashList *iterate_get_registered_Attachments(StrBuf *Target, WCTemplputParams *TP)
1273 return WC->attachments;
1276 void get_registered_Attachments_Count(StrBuf *Target, WCTemplputParams *TP)
1278 StrBufAppendPrintf(Target, "%ld", GetCount (WC->attachments));
1281 void servcmd_do_search(char *buf, long bufsize)
1283 snprintf(buf, bufsize, "MSGS SEARCH|%s", bstr("query"));
1286 void servcmd_headers(char *buf, long bufsize)
1288 snprintf(buf, bufsize, "MSGS ALL");
1291 void servcmd_readfwd(char *buf, long bufsize)
1293 snprintf(buf, bufsize, "MSGS ALL");
1296 void servcmd_readgt(char *buf, long bufsize)
1298 snprintf(buf, bufsize, "MSGS GT|%s", bstr("gt"));
1301 void servcmd_readlt(char *buf, long bufsize)
1303 snprintf(buf, bufsize, "MSGS LT|%s", bstr("lt"));
1306 void servcmd_readnew(char *buf, long bufsize)
1308 snprintf(buf, bufsize, "MSGS NEW");
1311 void servcmd_readold(char *buf, long bufsize)
1313 snprintf(buf, bufsize, "MSGS OLD");
1317 /* DO NOT REORDER OR REMOVE ANY OF THESE */
1318 readloop_struct rlid[] = {
1319 { {HKEY("do_search")}, servcmd_do_search },
1320 { {HKEY("headers")}, servcmd_headers },
1321 { {HKEY("readfwd")}, servcmd_readfwd },
1322 { {HKEY("readnew")}, servcmd_readnew },
1323 { {HKEY("readold")}, servcmd_readold },
1324 { {HKEY("readgt")}, servcmd_readgt },
1325 { {HKEY("readlt")}, servcmd_readlt }
1329 int ParseMessageListHeaders_Detail(StrBuf *Line,
1331 message_summary *Msg,
1332 StrBuf *ConversionBuffer)
1334 wcsession *WCC = WC;
1338 CheckConvertBufs(WCC);
1340 totallen = StrLength(Line);
1341 Msg->from = NewStrBufPlain(NULL, totallen);
1342 len = StrBufExtract_NextToken(ConversionBuffer, Line, pos, '|');
1344 /* Handle senders with RFC2047 encoding */
1345 StrBuf_RFC822_2_Utf8(Msg->from,
1347 WCC->DefaultCharset,
1354 len = StrBufExtract_NextToken(ConversionBuffer, Line, pos, '|');
1356 ( ((WCC->CurRoom.QRFlags & QR_NETWORK)
1357 || ((strcasecmp(ChrPtr(ConversionBuffer), ChrPtr(WCC->serv_info->serv_nodename))
1358 && (strcasecmp(ChrPtr(ConversionBuffer), ChrPtr(WCC->serv_info->serv_fqdn))))))))
1360 StrBufAppendBufPlain(Msg->from, HKEY(" @ "), 0);
1361 StrBufAppendBuf(Msg->from, ConversionBuffer, 0);
1364 /* Internet address (not used)
1365 * StrBufExtract_token(Msg->inetaddr, Line, 4, '|');
1367 StrBufSkip_NTokenS(Line, pos, '|', 1);
1368 Msg->subj = NewStrBufPlain(NULL, totallen);
1370 FlushStrBuf(ConversionBuffer);
1371 /* we assume the subject is the last parameter inside of the list;
1372 * thus we don't use the tokenizer to fetch it, since it will hick up
1373 * on tokenizer chars inside of the subjects
1374 StrBufExtract_NextToken(ConversionBuffer, Line, pos, '|');
1377 if (*pos != StrBufNOTNULL) {
1378 len = totallen - (*pos - ChrPtr(Line));
1379 StrBufPlain(ConversionBuffer, *pos, len);
1380 *pos = StrBufNOTNULL;
1382 (*(ChrPtr(ConversionBuffer) + len - 1) == '|'))
1383 StrBufCutRight(ConversionBuffer, 1);
1387 StrBufAppendBufPlain(Msg->subj, _("(no subject)"), -1,0);
1389 StrBuf_RFC822_2_Utf8(Msg->subj,
1391 WCC->DefaultCharset,
1401 int mailview_GetParamsGetServerCall(SharedMessageStatus *Stat,
1402 void **ViewSpecific,
1409 DoTemplate(HKEY("msg_listview"),NULL,&NoCtx);
1414 int mailview_Cleanup(void **ViewSpecific)
1416 /* Note: wDumpContent() will output one additional </div> tag. */
1417 /* We ought to move this out into template */
1424 int json_GetParamsGetServerCall(SharedMessageStatus *Stat,
1425 void **ViewSpecific,
1432 Stat->defaultsortorder = 2;
1434 Stat->load_seen = 1;
1435 /* Generally using maxmsgs|startmsg is not required
1436 in mailbox view, but we have a 'safemode' for clients
1437 (*cough* Exploder) that simply can't handle too many */
1438 if (havebstr("maxmsgs")) Stat->maxmsgs = ibstr("maxmsgs");
1439 else Stat->maxmsgs = 9999999;
1440 if (havebstr("startmsg")) Stat->startmsg = lbstr("startmsg");
1441 snprintf(cmd, len, "MSGS %s|%s||1",
1442 (oper == do_search) ? "SEARCH" : "ALL",
1443 (oper == do_search) ? bstr("query") : ""
1448 int json_MessageListHdr(SharedMessageStatus *Stat, void **ViewSpecific)
1450 /* TODO: make a generic function */
1451 hprintf("HTTP/1.1 200 OK\r\n");
1452 hprintf("Content-type: application/json; charset=utf-8\r\n");
1453 hprintf("Server: %s / %s\r\n", PACKAGE_STRING, ChrPtr(WC->serv_info->serv_software));
1454 hprintf("Connection: close\r\n");
1455 hprintf("Pragma: no-cache\r\nCache-Control: no-store\r\nExpires:-1\r\n");
1460 int json_RenderView_or_Tail(SharedMessageStatus *Stat,
1461 void **ViewSpecific,
1464 WCTemplputParams SubTP;
1466 memset(&SubTP, 0, sizeof(WCTemplputParams));
1467 DoTemplate(HKEY("mailsummary_json"),NULL, &SubTP);
1472 int json_Cleanup(void **ViewSpecific)
1474 /* Note: wDumpContent() will output one additional </div> tag. */
1475 /* We ought to move this out into template */
1484 InitModule_MSGRENDERERS
1487 RegisterReadLoopHandlerset(
1489 mailview_GetParamsGetServerCall,
1490 NULL, /* TODO: is this right? */
1492 ParseMessageListHeaders_Detail,
1497 RegisterReadLoopHandlerset(
1499 json_GetParamsGetServerCall,
1500 json_MessageListHdr,
1501 NULL, /* TODO: is this right? */
1502 ParseMessageListHeaders_Detail,
1504 json_RenderView_or_Tail,
1507 RegisterSortFunc(HKEY("date"),
1513 RegisterSortFunc(HKEY("subject"),
1519 RegisterSortFunc(HKEY("sender"),
1526 RegisterNamespace("SUMM:COUNT", 0, 0, tmplput_SUMM_COUNT, NULL, CTX_NONE);
1527 /* iterate over all known mails in WC->summ */
1528 RegisterIterator("MAIL:SUMM:MSGS", 0, NULL, iterate_get_mailsumm_All,
1529 NULL,NULL, CTX_MAILSUM, CTX_NONE, IT_NOFLAG);
1531 RegisterNamespace("MAIL:SUMM:EUID", 0, 1, tmplput_MAIL_SUMM_EUID, NULL, CTX_MAILSUM);
1532 RegisterNamespace("MAIL:SUMM:DATEBRIEF", 0, 0, tmplput_MAIL_SUMM_DATE_BRIEF, NULL, CTX_MAILSUM);
1533 RegisterNamespace("MAIL:SUMM:DATEFULL", 0, 0, tmplput_MAIL_SUMM_DATE_FULL, NULL, CTX_MAILSUM);
1534 RegisterNamespace("MAIL:SUMM:DATENO", 0, 0, tmplput_MAIL_SUMM_DATE_NO, NULL, CTX_MAILSUM);
1535 RegisterNamespace("MAIL:SUMM:N", 0, 0, tmplput_MAIL_SUMM_N, NULL, CTX_MAILSUM);
1536 RegisterNamespace("MAIL:SUMM:PERMALINK", 0, 0, tmplput_MAIL_SUMM_PERMALINK, NULL, CTX_MAILSUM);
1537 RegisterNamespace("MAIL:SUMM:FROM", 0, 2, tmplput_MAIL_SUMM_FROM, NULL, CTX_MAILSUM);
1538 RegisterNamespace("MAIL:SUMM:TO", 0, 2, tmplput_MAIL_SUMM_TO, NULL, CTX_MAILSUM);
1539 RegisterNamespace("MAIL:SUMM:SUBJECT", 0, 4, tmplput_MAIL_SUMM_SUBJECT, NULL, CTX_MAILSUM);
1540 RegisterNamespace("MAIL:SUMM:NTATACH", 0, 0, tmplput_MAIL_SUMM_NATTACH, NULL, CTX_MAILSUM);
1541 RegisterNamespace("MAIL:SUMM:CCCC", 0, 2, tmplput_MAIL_SUMM_CCCC, NULL, CTX_MAILSUM);
1542 RegisterNamespace("MAIL:SUMM:REPLYTO", 0, 2, tmplput_MAIL_SUMM_REPLYTO, NULL, CTX_MAILSUM);
1543 RegisterNamespace("MAIL:SUMM:H_NODE", 0, 2, tmplput_MAIL_SUMM_H_NODE, NULL, CTX_MAILSUM);
1544 RegisterNamespace("MAIL:SUMM:ALLRCPT", 0, 2, tmplput_MAIL_SUMM_ALLRCPT, NULL, CTX_MAILSUM);
1545 RegisterNamespace("MAIL:SUMM:ORGROOM", 0, 2, tmplput_MAIL_SUMM_ORGROOM, NULL, CTX_MAILSUM);
1546 RegisterNamespace("MAIL:SUMM:RFCA", 0, 2, tmplput_MAIL_SUMM_RFCA, NULL, CTX_MAILSUM);
1547 RegisterNamespace("MAIL:SUMM:OTHERNODE", 2, 0, tmplput_MAIL_SUMM_OTHERNODE, NULL, CTX_MAILSUM);
1548 RegisterNamespace("MAIL:SUMM:REFIDS", 0, 1, tmplput_MAIL_SUMM_REFIDS, NULL, CTX_MAILSUM);
1549 RegisterNamespace("MAIL:SUMM:INREPLYTO", 0, 2, tmplput_MAIL_SUMM_INREPLYTO, NULL, CTX_MAILSUM);
1550 RegisterNamespace("MAIL:BODY", 0, 2, tmplput_MAIL_BODY, NULL, CTX_MAILSUM);
1551 RegisterNamespace("MAIL:QUOTETEXT", 1, 2, tmplput_QUOTED_MAIL_BODY, NULL, CTX_NONE);
1552 RegisterNamespace("MAIL:EDITTEXT", 1, 2, tmplput_EDIT_MAIL_BODY, NULL, CTX_NONE);
1553 RegisterNamespace("MAIL:EDITWIKI", 1, 2, tmplput_EDIT_WIKI_BODY, NULL, CTX_NONE);
1554 RegisterConditional(HKEY("COND:MAIL:SUMM:RFCA"), 0, Conditional_MAIL_SUMM_RFCA, CTX_MAILSUM);
1555 RegisterConditional(HKEY("COND:MAIL:SUMM:CCCC"), 0, Conditional_MAIL_SUMM_CCCC, CTX_MAILSUM);
1556 RegisterConditional(HKEY("COND:MAIL:SUMM:REPLYTO"), 0, Conditional_MAIL_SUMM_REPLYTO, CTX_MAILSUM);
1557 RegisterConditional(HKEY("COND:MAIL:SUMM:UNREAD"), 0, Conditional_MAIL_SUMM_UNREAD, CTX_MAILSUM);
1558 RegisterConditional(HKEY("COND:MAIL:SUMM:H_NODE"), 0, Conditional_MAIL_SUMM_H_NODE, CTX_MAILSUM);
1559 RegisterConditional(HKEY("COND:MAIL:SUMM:OTHERNODE"), 0, Conditional_MAIL_SUMM_OTHERNODE, CTX_MAILSUM);
1560 RegisterConditional(HKEY("COND:MAIL:SUMM:SUBJECT"), 0, Conditional_MAIL_SUMM_SUBJECT, CTX_MAILSUM);
1561 RegisterConditional(HKEY("COND:MAIL:ANON"), 0, Conditional_ANONYMOUS_MESSAGE, CTX_MAILSUM);
1562 RegisterConditional(HKEY("COND:MAIL:TO"), 0, Conditional_MAIL_SUMM_TO, CTX_MAILSUM);
1563 RegisterConditional(HKEY("COND:MAIL:SUBJ"), 0, Conditional_MAIL_SUMM_SUBJ, CTX_MAILSUM);
1565 /* do we have mimetypes to iterate over? */
1566 RegisterConditional(HKEY("COND:MAIL:MIME:ATTACH"), 0, Conditional_MAIL_MIME_ALL, CTX_MAILSUM);
1567 RegisterConditional(HKEY("COND:MAIL:MIME:ATTACH:SUBMESSAGES"), 0, Conditional_MAIL_MIME_SUBMESSAGES, CTX_MAILSUM);
1568 RegisterConditional(HKEY("COND:MAIL:MIME:ATTACH:LINKS"), 0, Conditional_MAIL_MIME_ATTACHLINKS, CTX_MAILSUM);
1569 RegisterConditional(HKEY("COND:MAIL:MIME:ATTACH:ATT"), 0, Conditional_MAIL_MIME_ATTACH, CTX_MAILSUM);
1570 RegisterIterator("MAIL:MIME:ATTACH", 0, NULL, iterate_get_mime_All,
1571 NULL, NULL, CTX_MIME_ATACH, CTX_MAILSUM, IT_NOFLAG);
1572 RegisterIterator("MAIL:MIME:ATTACH:SUBMESSAGES", 0, NULL, iterate_get_mime_Submessages,
1573 NULL, NULL, CTX_MIME_ATACH, CTX_MAILSUM, IT_NOFLAG);
1574 RegisterIterator("MAIL:MIME:ATTACH:LINKS", 0, NULL, iterate_get_mime_AttachLinks,
1575 NULL, NULL, CTX_MIME_ATACH, CTX_MAILSUM, IT_NOFLAG);
1576 RegisterIterator("MAIL:MIME:ATTACH:ATT", 0, NULL, iterate_get_mime_Attachments,
1577 NULL, NULL, CTX_MIME_ATACH, CTX_MAILSUM, IT_NOFLAG);
1579 /* Parts of a mime attachent */
1580 RegisterNamespace("MAIL:MIME:NAME", 0, 2, tmplput_MIME_Name, NULL, CTX_MIME_ATACH);
1581 RegisterNamespace("MAIL:MIME:FILENAME", 0, 2, tmplput_MIME_FileName, NULL, CTX_MIME_ATACH);
1582 RegisterNamespace("MAIL:MIME:PARTNUM", 0, 2, tmplput_MIME_PartNum, NULL, CTX_MIME_ATACH);
1583 RegisterNamespace("MAIL:MIME:MSGNUM", 0, 2, tmplput_MIME_MsgNum, NULL, CTX_MIME_ATACH);
1584 RegisterNamespace("MAIL:MIME:DISPOSITION", 0, 2, tmplput_MIME_Disposition, NULL, CTX_MIME_ATACH);
1585 RegisterNamespace("MAIL:MIME:CONTENTTYPE", 0, 2, tmplput_MIME_ContentType, NULL, CTX_MIME_ATACH);
1586 RegisterNamespace("MAIL:MIME:CHARSET", 0, 2, tmplput_MIME_Charset, NULL, CTX_MIME_ATACH);
1587 RegisterNamespace("MAIL:MIME:LENGTH", 0, 2, tmplput_MIME_Length, NULL, CTX_MIME_ATACH);
1588 RegisterNamespace("MAIL:MIME:DATA", 0, 2, tmplput_MIME_Data, NULL, CTX_MIME_ATACH);
1589 /* load the actual attachment into WC->attachments; no output!!! */
1590 RegisterNamespace("MAIL:MIME:LOADDATA", 0, 0, tmplput_MIME_LoadData, NULL, CTX_MIME_ATACH);
1592 /* iterate the WC->attachments; use the above tokens for their contents */
1593 RegisterIterator("MSG:ATTACHNAMES", 0, NULL, iterate_get_registered_Attachments,
1594 NULL, NULL, CTX_MIME_ATACH, CTX_NONE, IT_NOFLAG);
1596 RegisterNamespace("MSG:NATTACH", 0, 0, get_registered_Attachments_Count, NULL, CTX_NONE);
1598 /* mime renderers translate an attachment into webcit viewable html text */
1599 RegisterMimeRenderer(HKEY("message/rfc822"), render_MAIL, 0, 150);
1600 RegisterMimeRenderer(HKEY("text/vnote"), render_MIME_VNote, 1, 300);
1601 RegisterMimeRenderer(HKEY("text/x-vcard"), render_MIME_VCard, 1, 201);
1602 RegisterMimeRenderer(HKEY("text/vcard"), render_MIME_VCard, 1, 200);
1603 RegisterMimeRenderer(HKEY("text/calendar"), render_MIME_ICS, 1, 501);
1604 RegisterMimeRenderer(HKEY("application/ics"), render_MIME_ICS, 1, 500);
1605 RegisterMimeRenderer(HKEY("text/x-citadel-variformat"), render_MAIL_variformat, 1, 2);
1606 RegisterMimeRenderer(HKEY("text/plain"), render_MAIL_text_plain, 1, 3);
1607 RegisterMimeRenderer(HKEY("text"), render_MAIL_text_plain, 1, 1);
1608 RegisterMimeRenderer(HKEY("text/html"), render_MAIL_html, 1, 100);
1609 RegisterMimeRenderer(HKEY(""), render_MAIL_UNKNOWN, 0, 0);
1611 /* these headers are citserver replies to MSG4 and friends. one evaluator for each */
1612 RegisterMsgHdr(HKEY("nhdr"), examine_nhdr, 0);
1613 RegisterMsgHdr(HKEY("type"), examine_type, 0);
1614 RegisterMsgHdr(HKEY("from"), examine_from, 0);
1615 RegisterMsgHdr(HKEY("subj"), examine_subj, 0);
1616 RegisterMsgHdr(HKEY("msgn"), examine_msgn, 0);
1617 RegisterMsgHdr(HKEY("wefw"), examine_wefw, 0);
1618 RegisterMsgHdr(HKEY("cccc"), examine_cccc, 0);
1619 RegisterMsgHdr(HKEY("rep2"), examine_replyto, 0);
1620 RegisterMsgHdr(HKEY("hnod"), examine_hnod, 0);
1621 RegisterMsgHdr(HKEY("room"), examine_room, 0);
1622 RegisterMsgHdr(HKEY("rfca"), examine_rfca, 0);
1623 RegisterMsgHdr(HKEY("node"), examine_node, 0);
1624 RegisterMsgHdr(HKEY("rcpt"), examine_rcpt, 0);
1625 RegisterMsgHdr(HKEY("time"), examine_time, 0);
1626 RegisterMsgHdr(HKEY("part"), examine_mime_part, 0);
1627 RegisterMsgHdr(HKEY("text"), examine_text, 1);
1628 /* these are the content-type headers we get infront of a message; put it into the same hash since it doesn't clash. */
1629 RegisterMsgHdr(HKEY("X-Citadel-MSG4-Partnum"), examine_msg4_partnum, 0);
1630 RegisterMsgHdr(HKEY("Content-type"), examine_content_type, 0);
1631 RegisterMsgHdr(HKEY("Content-length"), examine_content_lengh, 0);
1632 RegisterMsgHdr(HKEY("Content-transfer-encoding"), examine_content_encoding, 0); /* do we care? */
1633 RegisterMsgHdr(HKEY("charset"), examine_charset, 0);
1635 /* Don't care about these... */
1636 RegisterMsgHdr(HKEY("pref"), examine_pref, 0);
1637 RegisterMsgHdr(HKEY("suff"), examine_suff, 0);
1638 RegisterMsgHdr(HKEY("path"), examine_path, 0);
1642 InitModule2_MSGRENDERERS
1645 /* and finalize the anouncement to the server... */
1649 ServerStartModule_MSGRENDERERS
1652 MsgHeaderHandler = NewHash(1, NULL);
1653 MimeRenderHandler = NewHash(1, NULL);
1654 ReadLoopHandler = NewHash(1, NULL);
1658 ServerShutdownModule_MSGRENDERERS
1661 DeleteHash(&MsgHeaderHandler);
1662 DeleteHash(&MimeRenderHandler);
1663 DeleteHash(&ReadLoopHandler);
1669 SessionDestroyModule_MSGRENDERERS
1672 DeleteHash(&sess->attachments);
1673 FreeStrBuf(&sess->ConvertBuf1);
1674 FreeStrBuf(&sess->ConvertBuf2);