5 CtxType CTX_MAILSUM = CTX_NONE;
6 CtxType CTX_MIME_ATACH = CTX_NONE;
8 inline void CheckConvertBufs(struct wcsession *WCC)
10 if (WCC->ConvertBuf1 == NULL)
11 WCC->ConvertBuf1 = NewStrBuf();
12 if (WCC->ConvertBuf2 == NULL)
13 WCC->ConvertBuf2 = NewStrBuf();
17 * message index functions
21 void DestroyMimeParts(wc_mime_attachment *Mime)
23 FreeStrBuf(&Mime->Name);
24 FreeStrBuf(&Mime->FileName);
25 FreeStrBuf(&Mime->PartNum);
26 FreeStrBuf(&Mime->Disposition);
27 FreeStrBuf(&Mime->ContentType);
28 FreeStrBuf(&Mime->Charset);
29 FreeStrBuf(&Mime->Data);
32 void DestroyMime(void *vMime)
34 wc_mime_attachment *Mime = (wc_mime_attachment*)vMime;
35 DestroyMimeParts(Mime);
39 void DestroyMessageSummary(void *vMsg)
41 message_summary *Msg = (message_summary*) vMsg;
43 FreeStrBuf(&Msg->from);
45 FreeStrBuf(&Msg->subj);
46 FreeStrBuf(&Msg->reply_inreplyto);
47 FreeStrBuf(&Msg->reply_references);
48 FreeStrBuf(&Msg->cccc);
49 FreeStrBuf(&Msg->ReplyTo);
50 FreeStrBuf(&Msg->hnod);
51 FreeStrBuf(&Msg->AllRcpt);
52 FreeStrBuf(&Msg->Room);
53 FreeStrBuf(&Msg->Rfca);
54 FreeStrBuf(&Msg->OtherNode);
56 DeleteHash(&Msg->Attachments); /* list of Attachments */
57 DeleteHash(&Msg->Submessages);
58 DeleteHash(&Msg->AttachLinks);
59 DeleteHash(&Msg->AllAttach);
65 void RegisterMsgHdr(const char *HeaderName, long HdrNLen, ExamineMsgHeaderFunc evaluator, int type)
68 ev = (headereval*) malloc(sizeof(headereval));
69 ev->evaluator = evaluator;
71 Put(MsgHeaderHandler, HeaderName, HdrNLen, ev, NULL);
74 void RegisterMimeRenderer(const char *HeaderName, long HdrNLen,
75 RenderMimeFunc MimeRenderer,
79 RenderMimeFuncStruct *f;
81 f = (RenderMimeFuncStruct*) malloc(sizeof(RenderMimeFuncStruct));
83 Put(MimeRenderHandler, HeaderName, HdrNLen, f, NULL);
85 RegisterEmbeddableMimeType(HeaderName, HdrNLen, 10000 - Priority);
88 /*----------------------------------------------------------------------------*/
91 * comparator for two longs in descending order.
93 int longcmp_r(const void *s1, const void *s2) {
97 l1 = *(long *)GetSearchPayload(s1);
98 l2 = *(long *)GetSearchPayload(s2);
100 if (l1 > l2) return(-1);
101 if (l1 < l2) return(+1);
106 * comparator for longs; descending order.
108 int qlongcmp_r(const void *s1, const void *s2) {
112 if (l1 > l2) return(-1);
113 if (l1 < l2) return(+1);
119 * comparator for message summary structs by ascending subject.
121 int summcmp_subj(const void *s1, const void *s2) {
122 message_summary *summ1;
123 message_summary *summ2;
125 summ1 = (message_summary *)GetSearchPayload(s1);
126 summ2 = (message_summary *)GetSearchPayload(s2);
127 return strcasecmp(ChrPtr(summ1->subj), ChrPtr(summ2->subj));
131 * comparator for message summary structs by descending subject.
133 int summcmp_rsubj(const void *s1, const void *s2) {
134 message_summary *summ1;
135 message_summary *summ2;
137 summ1 = (message_summary *)GetSearchPayload(s1);
138 summ2 = (message_summary *)GetSearchPayload(s2);
139 return strcasecmp(ChrPtr(summ2->subj), ChrPtr(summ1->subj));
142 * comparator for message summary structs by descending subject.
144 int groupchange_subj(const void *s1, const void *s2) {
145 message_summary *summ1;
146 message_summary *summ2;
148 summ1 = (message_summary *)s1;
149 summ2 = (message_summary *)s2;
150 return ChrPtr(summ2->subj)[0] != ChrPtr(summ1->subj)[0];
154 * comparator for message summary structs by ascending sender.
156 int summcmp_sender(const void *s1, const void *s2) {
157 message_summary *summ1;
158 message_summary *summ2;
160 summ1 = (message_summary *)GetSearchPayload(s1);
161 summ2 = (message_summary *)GetSearchPayload(s2);
162 return strcasecmp(ChrPtr(summ1->from), ChrPtr(summ2->from));
166 * comparator for message summary structs by descending sender.
168 int summcmp_rsender(const void *s1, const void *s2) {
169 message_summary *summ1;
170 message_summary *summ2;
172 summ1 = (message_summary *)GetSearchPayload(s1);
173 summ2 = (message_summary *)GetSearchPayload(s2);
174 return strcasecmp(ChrPtr(summ2->from), ChrPtr(summ1->from));
177 * comparator for message summary structs by descending sender.
179 int groupchange_sender(const void *s1, const void *s2) {
180 message_summary *summ1;
181 message_summary *summ2;
183 summ1 = (message_summary *)s1;
184 summ2 = (message_summary *)s2;
185 return strcasecmp(ChrPtr(summ2->from), ChrPtr(summ1->from)) != 0;
190 * comparator for message summary structs by ascending date.
192 int summcmp_date(const void *s1, const void *s2) {
193 message_summary *summ1;
194 message_summary *summ2;
196 summ1 = (message_summary *)GetSearchPayload(s1);
197 summ2 = (message_summary *)GetSearchPayload(s2);
199 if (summ1->date < summ2->date) return -1;
200 else if (summ1->date > summ2->date) return +1;
205 * comparator for message summary structs by descending date.
207 int summcmp_rdate(const void *s1, const void *s2) {
208 message_summary *summ1;
209 message_summary *summ2;
211 summ1 = (message_summary *)GetSearchPayload(s1);
212 summ2 = (message_summary *)GetSearchPayload(s2);
214 if (summ1->date < summ2->date) return +1;
215 else if (summ1->date > summ2->date) return -1;
220 * comparator for message summary structs by descending date.
222 const long DAYSECONDS = 24 * 60 * 60;
223 int groupchange_date(const void *s1, const void *s2) {
224 message_summary *summ1;
225 message_summary *summ2;
227 summ1 = (message_summary *)s1;
228 summ2 = (message_summary *)s2;
230 return (summ1->date % DAYSECONDS) != (summ2->date %DAYSECONDS);
234 /*----------------------------------------------------------------------------*/
235 /* Don't wanna know... or? */
236 void examine_pref(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset) {return;}
237 void examine_suff(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset) {return;}
238 void examine_path(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset) {return;}
239 void examine_content_encoding(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
241 /* TODO: do we care? */
244 void examine_nhdr(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
247 if (!strncasecmp(ChrPtr(HdrLine), "yes", 8))
250 int Conditional_ANONYMOUS_MESSAGE(StrBuf *Target, WCTemplputParams *TP)
252 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
253 return Msg->nhdr != 0;
256 void examine_type(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
258 Msg->format_type = StrToi(HdrLine);
262 void examine_from(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
266 CheckConvertBufs(WCC);
267 FreeStrBuf(&Msg->from);
268 Msg->from = NewStrBufPlain(NULL, StrLength(HdrLine));
269 StrBuf_RFC822_2_Utf8(Msg->from,
276 void tmplput_MAIL_SUMM_FROM(StrBuf *Target, WCTemplputParams *TP)
278 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
279 StrBufAppendTemplate(Target, TP, Msg->from, 0);
282 void examine_subj(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
286 CheckConvertBufs(WCC);
287 FreeStrBuf(&Msg->subj);
288 Msg->subj = NewStrBufPlain(NULL, StrLength(HdrLine));
289 StrBuf_RFC822_2_Utf8(Msg->subj,
296 void tmplput_MAIL_SUMM_SUBJECT(StrBuf *Target, WCTemplputParams *TP)
298 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
300 if (TP->Tokens->nParameters == 4)
305 GetTemplateTokenString(Target, TP, 3, &pch, &len);
307 (strstr(ChrPtr(Msg->subj), pch) == NULL))
309 GetTemplateTokenString(Target, TP, 2, &pch, &len);
310 StrBufAppendBufPlain(Target, pch, len, 0);
313 StrBufAppendTemplate(Target, TP, Msg->subj, 0);
315 int Conditional_MAIL_SUMM_SUBJECT(StrBuf *Target, WCTemplputParams *TP)
317 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
320 return StrLength(Msg->subj) > 0;
324 void examine_msgn(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
328 CheckConvertBufs(WCC);
329 FreeStrBuf(&Msg->reply_inreplyto);
330 Msg->reply_inreplyto = NewStrBufPlain(NULL, StrLength(HdrLine));
331 StrBuf_RFC822_2_Utf8(Msg->reply_inreplyto,
338 void tmplput_MAIL_SUMM_INREPLYTO(StrBuf *Target, WCTemplputParams *TP)
340 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
341 StrBufAppendTemplate(Target, TP, Msg->reply_inreplyto, 0);
344 int Conditional_MAIL_SUMM_UNREAD(StrBuf *Target, WCTemplputParams *TP)
346 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
347 return (Msg->Flags & MSGFLAG_READ) != 0;
350 void examine_wefw(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
354 CheckConvertBufs(WCC);
355 FreeStrBuf(&Msg->reply_references);
356 Msg->reply_references = NewStrBufPlain(NULL, StrLength(HdrLine));
357 StrBuf_RFC822_2_Utf8(Msg->reply_references,
364 void tmplput_MAIL_SUMM_REFIDS(StrBuf *Target, WCTemplputParams *TP)
366 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
367 StrBufAppendTemplate(Target, TP, Msg->reply_references, 0);
370 void examine_replyto(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
374 CheckConvertBufs(WCC);
375 FreeStrBuf(&Msg->ReplyTo);
376 Msg->ReplyTo = NewStrBufPlain(NULL, StrLength(HdrLine));
377 StrBuf_RFC822_2_Utf8(Msg->ReplyTo,
383 if (Msg->AllRcpt == NULL)
384 Msg->AllRcpt = NewStrBufPlain(NULL, StrLength(HdrLine));
385 if (StrLength(Msg->AllRcpt) > 0) {
386 StrBufAppendBufPlain(Msg->AllRcpt, HKEY(", "), 0);
388 StrBufAppendBuf(Msg->AllRcpt, Msg->ReplyTo, 0);
390 void tmplput_MAIL_SUMM_REPLYTO(StrBuf *Target, WCTemplputParams *TP)
392 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
393 StrBufAppendTemplate(Target, TP, Msg->ReplyTo, 0);
396 void examine_cccc(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
400 CheckConvertBufs(WCC);
401 FreeStrBuf(&Msg->cccc);
402 Msg->cccc = NewStrBufPlain(NULL, StrLength(HdrLine));
403 StrBuf_RFC822_2_Utf8(Msg->cccc,
409 if (Msg->AllRcpt == NULL)
410 Msg->AllRcpt = NewStrBufPlain(NULL, StrLength(HdrLine));
411 if (StrLength(Msg->AllRcpt) > 0) {
412 StrBufAppendBufPlain(Msg->AllRcpt, HKEY(", "), 0);
414 StrBufAppendBuf(Msg->AllRcpt, Msg->cccc, 0);
416 void tmplput_MAIL_SUMM_CCCC(StrBuf *Target, WCTemplputParams *TP)
418 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
419 StrBufAppendTemplate(Target, TP, Msg->cccc, 0);
423 void examine_room(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
425 if ((StrLength(HdrLine) > 0) &&
426 (strcasecmp(ChrPtr(HdrLine), ChrPtr(WC->CurRoom.name)))) {
427 FreeStrBuf(&Msg->Room);
428 Msg->Room = NewStrBufDup(HdrLine);
431 void tmplput_MAIL_SUMM_ORGROOM(StrBuf *Target, WCTemplputParams *TP)
433 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
434 StrBufAppendTemplate(Target, TP, Msg->Room, 0);
438 void examine_rfca(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
440 FreeStrBuf(&Msg->Rfca);
441 Msg->Rfca = NewStrBufDup(HdrLine);
443 void tmplput_MAIL_SUMM_RFCA(StrBuf *Target, WCTemplputParams *TP)
445 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
446 StrBufAppendTemplate(Target, TP, Msg->Rfca, 0);
448 int Conditional_MAIL_SUMM_RFCA(StrBuf *Target, WCTemplputParams *TP)
450 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
451 return StrLength(Msg->Rfca) > 0;
453 int Conditional_MAIL_SUMM_CCCC(StrBuf *Target, WCTemplputParams *TP)
455 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
456 return StrLength(Msg->cccc) > 0;
458 int Conditional_MAIL_SUMM_REPLYTO(StrBuf *Target, WCTemplputParams *TP)
460 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
461 return StrLength(Msg->ReplyTo) > 0;
464 void examine_node(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
468 if ( (StrLength(HdrLine) > 0) &&
469 ((WC->CurRoom.QRFlags & QR_NETWORK)
470 || ((strcasecmp(ChrPtr(HdrLine), ChrPtr(WCC->serv_info->serv_nodename))
471 && (strcasecmp(ChrPtr(HdrLine), ChrPtr(WCC->serv_info->serv_fqdn))))))) {
472 FreeStrBuf(&Msg->OtherNode);
473 Msg->OtherNode = NewStrBufDup(HdrLine);
476 void tmplput_MAIL_SUMM_OTHERNODE(StrBuf *Target, WCTemplputParams *TP)
478 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
479 StrBufAppendTemplate(Target, TP, Msg->OtherNode, 0);
481 int Conditional_MAIL_SUMM_OTHERNODE(StrBuf *Target, WCTemplputParams *TP)
483 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
484 return StrLength(Msg->OtherNode) > 0;
488 void examine_rcpt(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
492 CheckConvertBufs(WCC);
493 FreeStrBuf(&Msg->to);
494 Msg->to = NewStrBufPlain(NULL, StrLength(HdrLine));
495 StrBuf_RFC822_2_Utf8(Msg->to,
501 if (Msg->AllRcpt == NULL)
502 Msg->AllRcpt = NewStrBufPlain(NULL, StrLength(HdrLine));
503 if (StrLength(Msg->AllRcpt) > 0) {
504 StrBufAppendBufPlain(Msg->AllRcpt, HKEY(", "), 0);
506 StrBufAppendBuf(Msg->AllRcpt, Msg->to, 0);
508 void tmplput_MAIL_SUMM_TO(StrBuf *Target, WCTemplputParams *TP)
510 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
511 StrBufAppendTemplate(Target, TP, Msg->to, 0);
513 int Conditional_MAIL_SUMM_TO(StrBuf *Target, WCTemplputParams *TP)
515 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
516 return StrLength(Msg->to) != 0;
518 int Conditional_MAIL_SUMM_SUBJ(StrBuf *Target, WCTemplputParams *TP)
520 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
521 return StrLength(Msg->subj) != 0;
523 void tmplput_MAIL_SUMM_ALLRCPT(StrBuf *Target, WCTemplputParams *TP)
525 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
526 StrBufAppendTemplate(Target, TP, Msg->AllRcpt, 0);
531 void tmplput_SUMM_COUNT(StrBuf *Target, WCTemplputParams *TP)
533 StrBufAppendPrintf(Target, "%d", GetCount( WC->summ));
536 HashList *iterate_get_mailsumm_All(StrBuf *Target, WCTemplputParams *TP)
540 void examine_time(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
542 Msg->date = StrTol(HdrLine);
545 void tmplput_MAIL_SUMM_DATE_BRIEF(StrBuf *Target, WCTemplputParams *TP)
548 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
549 webcit_fmt_date(datebuf, 64, Msg->date, DATEFMT_BRIEF);
550 StrBufAppendBufPlain(Target, datebuf, -1, 0);
553 void tmplput_MAIL_SUMM_EUID(StrBuf *Target, WCTemplputParams *TP)
555 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
556 StrBufAppendTemplate(Target, TP, Msg->euid, 0);
559 void tmplput_MAIL_SUMM_DATE_FULL(StrBuf *Target, WCTemplputParams *TP)
562 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
563 webcit_fmt_date(datebuf, 64, Msg->date, DATEFMT_FULL);
564 StrBufAppendBufPlain(Target, datebuf, -1, 0);
566 void tmplput_MAIL_SUMM_DATE_NO(StrBuf *Target, WCTemplputParams *TP)
568 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
569 StrBufAppendPrintf(Target, "%ld", Msg->date, 0);
574 void render_MAIL(StrBuf *Target, WCTemplputParams *TP, StrBuf *FoundCharset)
576 wc_mime_attachment *Mime = (wc_mime_attachment *) CTX(CTX_MIME_ATACH);
577 const StrBuf *TemplateMime;
579 if (Mime->Data == NULL)
580 Mime->Data = NewStrBufPlain(NULL, Mime->length);
582 FlushStrBuf(Mime->Data);
583 read_message(Mime->Data, HKEY("view_submessage"), Mime->msgnum, Mime->PartNum, &TemplateMime);
585 if ( (!IsEmptyStr(mime_submessages)) && (!section[0]) ) {
586 for (i=0; i<num_tokens(mime_submessages, '|'); ++i) {
587 extract_token(buf, mime_submessages, i, '|', sizeof buf);
588 / ** use printable_view to suppress buttons * /
589 wc_printf("<blockquote>");
590 read_message(Mime->msgnum, 1, ChrPtr(Mime->Section));
591 wc_printf("</blockquote>");
597 void render_MIME_VCard(StrBuf *Target, WCTemplputParams *TP, StrBuf *FoundCharset)
599 wc_mime_attachment *Mime = (wc_mime_attachment *) CTX(CTX_MIME_ATACH);
601 if (StrLength(Mime->Data) == 0)
603 if (StrLength(Mime->Data) > 0) {
606 /** If it's my vCard I can edit it */
607 if ( (!strcasecmp(ChrPtr(WCC->CurRoom.name), USERCONFIGROOM))
608 || (!strcasecmp(&(ChrPtr(WCC->CurRoom.name)[11]), USERCONFIGROOM))
609 || (WC->CurRoom.view == VIEW_ADDRESSBOOK)
611 StrBufAppendPrintf(Buf, "<a href=\"edit_vcard?msgnum=%ld?partnum=%s\">",
612 Mime->msgnum, ChrPtr(Mime->PartNum));
613 StrBufAppendPrintf(Buf, "[%s]</a>", _("edit"));
616 /* In all cases, display the full card */
617 display_vcard(Buf, Mime, 0, 1, NULL, -1);
618 FreeStrBuf(&Mime->Data);
624 void render_MIME_ICS(StrBuf *Target, WCTemplputParams *TP, StrBuf *FoundCharset)
626 wc_mime_attachment *Mime = (wc_mime_attachment *) CTX(CTX_MIME_ATACH);
627 if (StrLength(Mime->Data) == 0) {
630 if (StrLength(Mime->Data) > 0) {
631 cal_process_attachment(Mime);
637 void examine_mime_part(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
639 const char *Ptr = NULL;
640 wc_mime_attachment *Mime;
644 CheckConvertBufs(WCC);
645 Mime = (wc_mime_attachment*) malloc(sizeof(wc_mime_attachment));
646 memset(Mime, 0, sizeof(wc_mime_attachment));
647 Mime->msgnum = Msg->msgnum;
650 Mime->Name = NewStrBuf();
651 StrBufExtract_NextToken(Buf, HdrLine, &Ptr, '|');
652 StrBuf_RFC822_2_Utf8(Mime->Name,
658 StrBufTrim(Mime->Name);
660 StrBufExtract_NextToken(Buf, HdrLine, &Ptr, '|');
661 Mime->FileName = NewStrBuf();
662 StrBuf_RFC822_2_Utf8(Mime->FileName,
668 StrBufTrim(Mime->FileName);
670 Mime->PartNum = NewStrBuf();
671 StrBufExtract_NextToken(Mime->PartNum, HdrLine, &Ptr, '|');
672 StrBufTrim(Mime->PartNum);
673 if (strchr(ChrPtr(Mime->PartNum), '.') != NULL)
678 Mime->Disposition = NewStrBuf();
679 StrBufExtract_NextToken(Mime->Disposition, HdrLine, &Ptr, '|');
681 Mime->ContentType = NewStrBuf();
682 StrBufExtract_NextToken(Mime->ContentType, HdrLine, &Ptr, '|');
683 StrBufTrim(Mime->ContentType);
684 StrBufLowerCase(Mime->ContentType);
685 if (!strcmp(ChrPtr(Mime->ContentType), "application/octet-stream")) {
686 StrBufPlain(Mime->ContentType,
687 GuessMimeByFilename(SKEY(Mime->FileName)), -1);
690 Mime->length = StrBufExtractNext_int(HdrLine, &Ptr, '|');
692 StrBufSkip_NTokenS(HdrLine, &Ptr, '|', 1); /* cbid?? */
694 Mime->Charset = NewStrBuf();
695 StrBufExtract_NextToken(Mime->Charset, HdrLine, &Ptr, '|');
698 if ( (StrLength(Mime->FileName) == 0) && (StrLength(Mime->Name) > 0) ) {
699 StrBufAppendBuf(Mime->FileName, Mime->Name, 0);
702 if (StrLength(Msg->PartNum) > 0) {
704 StrBufPrintf(Buf, "%s.%s", ChrPtr(Msg->PartNum), ChrPtr(Mime->PartNum));
710 if (Msg->AllAttach == NULL)
711 Msg->AllAttach = NewHash(1,NULL);
712 Put(Msg->AllAttach, SKEY(Mime->PartNum), Mime, DestroyMime);
717 void evaluate_mime_part(StrBuf *Target, WCTemplputParams *TP)
719 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
720 wc_mime_attachment *Mime = (wc_mime_attachment *) CTX(CTX_MIME_ATACH);
723 /* just print the root-node */
724 if ((Mime->level >= 1) &&
725 GetHash(MimeRenderHandler, SKEY(Mime->ContentType), &vMimeRenderer) &&
726 vMimeRenderer != NULL)
728 Mime->Renderer = (RenderMimeFuncStruct*) vMimeRenderer;
729 if (Msg->Submessages == NULL)
730 Msg->Submessages = NewHash(1,NULL);
731 Put(Msg->Submessages, SKEY(Mime->PartNum), Mime, reference_free_handler);
733 else if ((Mime->level >= 1) &&
734 (!strcasecmp(ChrPtr(Mime->Disposition), "inline"))
735 && (!strncasecmp(ChrPtr(Mime->ContentType), "image/", 6)) ){
736 if (Msg->AttachLinks == NULL)
737 Msg->AttachLinks = NewHash(1,NULL);
738 Put(Msg->AttachLinks, SKEY(Mime->PartNum), Mime, reference_free_handler);
740 else if ((Mime->level >= 1) &&
741 (StrLength(Mime->ContentType) > 0) &&
742 ( (!strcasecmp(ChrPtr(Mime->Disposition), "attachment"))
743 || (!strcasecmp(ChrPtr(Mime->Disposition), "inline"))
744 || (!strcasecmp(ChrPtr(Mime->Disposition), ""))))
746 if (Msg->AttachLinks == NULL)
747 Msg->AttachLinks = NewHash(1,NULL);
748 Put(Msg->AttachLinks, SKEY(Mime->PartNum), Mime, reference_free_handler);
749 if ((strcasecmp(ChrPtr(Mime->ContentType), "application/octet-stream") == 0) &&
750 (StrLength(Mime->FileName) > 0)) {
751 FlushStrBuf(Mime->ContentType);
752 StrBufAppendBufPlain(Mime->ContentType,
753 GuessMimeByFilename(SKEY(Mime->FileName)),
759 void tmplput_MAIL_SUMM_NATTACH(StrBuf *Target, WCTemplputParams *TP)
761 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
762 StrBufAppendPrintf(Target, "%ld", GetCount(Msg->Attachments));
766 void examine_hnod(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
770 CheckConvertBufs(WCC);
771 FreeStrBuf(&Msg->hnod);
772 Msg->hnod = NewStrBufPlain(NULL, StrLength(HdrLine));
773 StrBuf_RFC822_2_Utf8(Msg->hnod,
780 void tmplput_MAIL_SUMM_H_NODE(StrBuf *Target, WCTemplputParams *TP)
782 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
783 StrBufAppendTemplate(Target, TP, Msg->hnod, 0);
785 int Conditional_MAIL_SUMM_H_NODE(StrBuf *Target, WCTemplputParams *TP)
787 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
788 return StrLength(Msg->hnod) > 0;
793 void examine_text(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
795 if (Msg->MsgBody->Data == NULL)
796 Msg->MsgBody->Data = NewStrBufPlain(NULL, SIZ);
798 FlushStrBuf(Msg->MsgBody->Data);
801 void examine_msg4_partnum(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
803 Msg->MsgBody->PartNum = NewStrBufDup(HdrLine);
804 StrBufTrim(Msg->MsgBody->PartNum);
807 void examine_content_lengh(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
809 Msg->MsgBody->length = StrTol(HdrLine);
810 Msg->MsgBody->size_known = 1;
813 void examine_content_type(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
823 Msg->MsgBody->ContentType = NewStrBufDup(HdrLine);
824 sem = strchr(ChrPtr(HdrLine), ';');
827 Token = NewStrBufPlain(NULL, StrLength(HdrLine));
828 Value = NewStrBufPlain(NULL, StrLength(HdrLine));
829 len = sem - ChrPtr(HdrLine);
830 StrBufCutAt(Msg->MsgBody->ContentType, len, NULL);
831 while (sem != NULL) {
832 while (isspace(*(sem + 1)))
834 StrBufCutLeft(HdrLine, sem - ChrPtr(HdrLine));
835 sem = strchr(ChrPtr(HdrLine), ';');
837 len = sem - ChrPtr(HdrLine);
839 len = StrLength(HdrLine);
842 StrBufAppendBufPlain(Token, ChrPtr(HdrLine), len, 0);
843 eq = strchr(ChrPtr(Token), '=');
845 len = eq - ChrPtr(Token);
846 StrBufAppendBufPlain(Value, eq + 1, StrLength(Token) - len - 1, 0);
847 StrBufCutAt(Token, len, NULL);
852 if (GetHash(MsgHeaderHandler, SKEY(Token), &vHdr) &&
854 Hdr = (headereval*)vHdr;
855 Hdr->evaluator(Msg, Value, FoundCharset);
857 else syslog(1, "don't know how to handle content type sub-header[%s]\n", ChrPtr(Token));
864 void tmplput_MAIL_SUMM_N(StrBuf *Target, WCTemplputParams *TP)
866 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
867 StrBufAppendPrintf(Target, "%ld", Msg->msgnum);
871 void tmplput_MAIL_SUMM_PERMALINK(StrBuf *Target, WCTemplputParams *TP)
873 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
874 char perma_link[1024];
876 strcpy(perma_link, "/readfwd?go=");
877 urlesc(&perma_link[12], sizeof(perma_link) - 12, (char *)ChrPtr(WC->CurRoom.name) );
878 sprintf(&perma_link[strlen(perma_link)], "?start_reading_at=%ld#%ld", Msg->msgnum, Msg->msgnum);
879 StrBufAppendPrintf(Target, "%s", perma_link);
883 int Conditional_MAIL_MIME_ALL(StrBuf *Target, WCTemplputParams *TP)
885 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
886 return GetCount(Msg->Attachments) > 0;
889 int Conditional_MAIL_MIME_SUBMESSAGES(StrBuf *Target, WCTemplputParams *TP)
891 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
892 return GetCount(Msg->Submessages) > 0;
895 int Conditional_MAIL_MIME_ATTACHLINKS(StrBuf *Target, WCTemplputParams *TP)
897 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
898 return GetCount(Msg->AttachLinks) > 0;
901 int Conditional_MAIL_MIME_ATTACH(StrBuf *Target, WCTemplputParams *TP)
903 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
904 return GetCount(Msg->AllAttach) > 0;
907 void tmplput_QUOTED_MAIL_BODY(StrBuf *Target, WCTemplputParams *TP)
913 MsgNum = LBstr(TKEY(0));
915 read_message(Buf, HKEY("view_message_replyquote"), MsgNum, NULL, &Mime);
916 StrBufAppendTemplate(Target, TP, Buf, 1);
920 void tmplput_EDIT_MAIL_BODY(StrBuf *Target, WCTemplputParams *TP)
926 MsgNum = LBstr(TKEY(0));
928 read_message(Buf, HKEY("view_message_edit"), MsgNum, NULL, &Mime);
929 StrBufAppendTemplate(Target, TP, Buf, 1);
933 void tmplput_EDIT_WIKI_BODY(StrBuf *Target, WCTemplputParams *TP)
939 /* Insert the existing content of the wiki page into the editor. But we only want
940 * to do this the first time -- if the user is uploading an attachment we don't want
943 if (!havebstr("attach_button")) {
944 char *wikipage = strdup(bstr("page"));
945 str_wiki_index(wikipage);
946 msgnum = locate_message_by_uid(wikipage);
950 read_message(Buf, HKEY("view_message_wikiedit"), msgnum, NULL, &Mime);
951 StrBufAppendTemplate(Target, TP, Buf, 1);
957 void tmplput_MAIL_BODY(StrBuf *Target, WCTemplputParams *TP)
959 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
960 StrBufAppendTemplate(Target, TP, Msg->MsgBody->Data, 0);
964 void render_MAIL_variformat(StrBuf *Target, WCTemplputParams *TP, StrBuf *FoundCharset)
966 /* Messages in legacy Citadel variformat get handled thusly... */
967 wc_mime_attachment *Mime = (wc_mime_attachment *) CTX(CTX_MIME_ATACH);
968 StrBuf *TTarget = NewStrBufPlain(NULL, StrLength(Mime->Data));
969 FmOut(TTarget, "JUSTIFY", Mime->Data);
970 FreeStrBuf(&Mime->Data);
971 Mime->Data = TTarget;
974 void render_MAIL_text_plain(StrBuf *Target, WCTemplputParams *TP, StrBuf *FoundCharset)
976 wc_mime_attachment *Mime = (wc_mime_attachment *) CTX(CTX_MIME_ATACH);
977 const char *ptr, *pte;
978 const char *BufPtr = NULL;
992 iconv_t ic = (iconv_t)(-1) ;
995 if ((StrLength(Mime->Data) == 0) && (Mime->length > 0)) {
996 FreeStrBuf(&Mime->Data);
1002 if (StrLength(Mime->Charset) != 0)
1004 else if (StrLength(FoundCharset) > 0)
1006 else if (StrLength(WC->DefaultCharset) > 0)
1007 cs = WC->DefaultCharset;
1011 else if (!strcasecmp(ChrPtr(cs), "utf-8")) {
1014 else if (!strcasecmp(ChrPtr(cs), "us-ascii")) {
1018 ctdl_iconv_open("UTF-8", ChrPtr(cs), &ic);
1019 if (ic == (iconv_t)(-1) ) {
1020 syslog(5, "%s:%d iconv_open(UTF-8, %s) failed: %s\n",
1021 __FILE__, __LINE__, ChrPtr(Mime->Charset), strerror(errno));
1026 Line = NewStrBufPlain(NULL, SIZ);
1027 Line1 = NewStrBufPlain(NULL, SIZ);
1028 Line2 = NewStrBufPlain(NULL, SIZ);
1029 TTarget = NewStrBufPlain(NULL, StrLength(Mime->Data));
1032 if (StrLength(Mime->Data) > 0)
1035 StrBufSipLine(Line, Mime->Data, &BufPtr);
1039 len = StrLength(Line);
1042 while ((ptr < pte) &&
1051 if (i > 0) StrBufCutLeft(Line, i);
1053 if (StrLength(Line) == 0) {
1056 StrBufAppendBufPlain(TTarget, HKEY("<tt></tt><br>\n"), 0);
1062 for (i = bn; i < bq; i++)
1063 StrBufAppendBufPlain(TTarget, HKEY("<blockquote>"), 0);
1064 for (i = bq; i < bn; i++)
1065 StrBufAppendBufPlain(TTarget, HKEY("</blockquote>"), 0);
1068 StrBufConvert(Line, Line1, &ic);
1071 StrBufAppendBufPlain(TTarget, HKEY("<tt>"), 0);
1072 UrlizeText(Line1, Line, Line2);
1074 StrEscAppend(TTarget, Line1, NULL, 0, 0);
1075 StrBufAppendBufPlain(TTarget, HKEY("</tt><br>\n"), 0);
1079 while ((BufPtr != StrBufNOTNULL) &&
1082 if (nEmptyLines > 0)
1083 StrBufCutRight(TTarget, nEmptyLines * (sizeof ("<tt></tt><br>\n") - 1));
1084 for (i = 0; i < bn; i++)
1085 StrBufAppendBufPlain(TTarget, HKEY("</blockquote>"), 0);
1087 StrBufAppendBufPlain(TTarget, HKEY("</i><br>"), 0);
1089 if (ic != (iconv_t)(-1) ) {
1094 FreeStrBuf(&Mime->Data);
1095 Mime->Data = TTarget;
1096 FlushStrBuf(Mime->ContentType);
1097 StrBufAppendBufPlain(Mime->ContentType, HKEY("text/html"), 0);
1098 FlushStrBuf(Mime->Charset);
1099 StrBufAppendBufPlain(Mime->Charset, HKEY("UTF-8"), 0);
1105 void render_MAIL_html(StrBuf *Target, WCTemplputParams *TP, StrBuf *FoundCharset)
1107 wc_mime_attachment *Mime = (wc_mime_attachment *) CTX(CTX_MIME_ATACH);
1110 if (StrLength(Mime->Data) == 0)
1113 Buf = NewStrBufPlain(NULL, StrLength(Mime->Data));
1115 /* HTML is fun, but we've got to strip it first */
1116 output_html(ChrPtr(Mime->Charset),
1117 (WC->CurRoom.view == VIEW_WIKI ? 1 : 0),
1120 FreeStrBuf(&Mime->Data);
1124 void render_MAIL_UNKNOWN(StrBuf *Target, WCTemplputParams *TP, StrBuf *FoundCharset)
1126 wc_mime_attachment *Mime = (wc_mime_attachment *) CTX(CTX_MIME_ATACH);
1127 /* Unknown weirdness */
1128 FlushStrBuf(Mime->Data);
1129 StrBufAppendBufPlain(Mime->Data, _("I don't know how to display "), -1, 0);
1130 StrBufAppendBuf(Mime->Data, Mime->ContentType, 0);
1131 StrBufAppendBufPlain(Mime->Data, HKEY("<br>\n"), 0);
1135 HashList *iterate_get_mime_All(StrBuf *Target, WCTemplputParams *TP)
1137 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
1138 return Msg->Attachments;
1140 HashList *iterate_get_mime_Submessages(StrBuf *Target, WCTemplputParams *TP)
1142 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
1143 return Msg->Submessages;
1145 HashList *iterate_get_mime_AttachLinks(StrBuf *Target, WCTemplputParams *TP)
1147 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
1148 return Msg->AttachLinks;
1150 HashList *iterate_get_mime_Attachments(StrBuf *Target, WCTemplputParams *TP)
1152 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
1153 return Msg->AllAttach;
1156 void tmplput_MIME_Name(StrBuf *Target, WCTemplputParams *TP)
1158 wc_mime_attachment *mime = (wc_mime_attachment*) CTX(CTX_MIME_ATACH);
1159 StrBufAppendTemplate(Target, TP, mime->Name, 0);
1162 void tmplput_MIME_FileName(StrBuf *Target, WCTemplputParams *TP)
1164 wc_mime_attachment *mime = (wc_mime_attachment*) CTX(CTX_MIME_ATACH);
1165 StrBufAppendTemplate(Target, TP, mime->FileName, 0);
1168 void tmplput_MIME_PartNum(StrBuf *Target, WCTemplputParams *TP)
1170 wc_mime_attachment *mime = (wc_mime_attachment*) CTX(CTX_MIME_ATACH);
1171 StrBufAppendTemplate(Target, TP, mime->PartNum, 0);
1174 void tmplput_MIME_MsgNum(StrBuf *Target, WCTemplputParams *TP)
1176 wc_mime_attachment *mime = (wc_mime_attachment*) CTX(CTX_MIME_ATACH);
1177 StrBufAppendPrintf(Target, "%ld", mime->msgnum);
1180 void tmplput_MIME_Disposition(StrBuf *Target, WCTemplputParams *TP)
1182 wc_mime_attachment *mime = (wc_mime_attachment*) CTX(CTX_MIME_ATACH);
1183 StrBufAppendTemplate(Target, TP, mime->Disposition, 0);
1186 void tmplput_MIME_ContentType(StrBuf *Target, WCTemplputParams *TP)
1188 wc_mime_attachment *mime = (wc_mime_attachment*) CTX(CTX_MIME_ATACH);
1189 StrBufAppendTemplate(Target, TP, mime->ContentType, 0);
1192 void examine_charset(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
1194 Msg->MsgBody->Charset = NewStrBufDup(HdrLine);
1197 void tmplput_MIME_Charset(StrBuf *Target, WCTemplputParams *TP)
1199 wc_mime_attachment *mime = (wc_mime_attachment*) CTX(CTX_MIME_ATACH);
1200 StrBufAppendTemplate(Target, TP, mime->Charset, 0);
1203 void tmplput_MIME_Data(StrBuf *Target, WCTemplputParams *TP)
1205 wc_mime_attachment *mime = (wc_mime_attachment*) CTX(CTX_MIME_ATACH);
1206 if (mime->Renderer != NULL)
1207 mime->Renderer->f(Target, TP, NULL);
1208 StrBufAppendTemplate(Target, TP, mime->Data, 0);
1209 /* TODO: check whether we need to load it now? */
1212 void tmplput_MIME_LoadData(StrBuf *Target, WCTemplputParams *TP)
1214 wcsession *WCC = WC;
1215 wc_mime_attachment *mime = (wc_mime_attachment*) CTX(CTX_MIME_ATACH);
1216 wc_mime_attachment *att;
1218 if (( (!strcasecmp(ChrPtr(mime->Disposition), "inline"))||
1219 (!strcasecmp(ChrPtr(mime->Disposition), "attachment"))) &&
1220 (strcasecmp(ChrPtr(mime->ContentType), "application/ms-tnef")!=0))
1225 /* steal this mime part... */
1226 att = malloc(sizeof(wc_mime_attachment));
1227 memcpy(att, mime, sizeof(wc_mime_attachment));
1228 memset(mime, 0, sizeof(wc_mime_attachment));
1230 if (att->Data == NULL)
1233 if (WCC->attachments == NULL)
1234 WCC->attachments = NewHash(1, NULL);
1235 /* And add it to the list. */
1236 n = snprintf(N, sizeof N, "%d", GetCount(WCC->attachments) + 1);
1237 Put(WCC->attachments, N, n, att, DestroyMime);
1241 void tmplput_MIME_Length(StrBuf *Target, WCTemplputParams *TP)
1243 wc_mime_attachment *mime = (wc_mime_attachment*) CTX(CTX_MIME_ATACH);
1244 StrBufAppendPrintf(Target, "%ld", mime->length);
1247 HashList *iterate_get_registered_Attachments(StrBuf *Target, WCTemplputParams *TP)
1249 return WC->attachments;
1252 void get_registered_Attachments_Count(StrBuf *Target, WCTemplputParams *TP)
1254 StrBufAppendPrintf(Target, "%ld", GetCount (WC->attachments));
1257 void servcmd_do_search(char *buf, long bufsize)
1259 snprintf(buf, bufsize, "MSGS SEARCH|%s", bstr("query"));
1262 void servcmd_headers(char *buf, long bufsize)
1264 snprintf(buf, bufsize, "MSGS ALL");
1267 void servcmd_readfwd(char *buf, long bufsize)
1269 snprintf(buf, bufsize, "MSGS ALL");
1272 void servcmd_readgt(char *buf, long bufsize)
1274 snprintf(buf, bufsize, "MSGS GT|%s", bstr("gt"));
1277 void servcmd_readlt(char *buf, long bufsize)
1279 snprintf(buf, bufsize, "MSGS LT|%s", bstr("lt"));
1282 void servcmd_readnew(char *buf, long bufsize)
1284 snprintf(buf, bufsize, "MSGS NEW");
1287 void servcmd_readold(char *buf, long bufsize)
1289 snprintf(buf, bufsize, "MSGS OLD");
1293 /* DO NOT REORDER OR REMOVE ANY OF THESE */
1294 readloop_struct rlid[] = {
1295 { {HKEY("do_search")}, servcmd_do_search },
1296 { {HKEY("headers")}, servcmd_headers },
1297 { {HKEY("readfwd")}, servcmd_readfwd },
1298 { {HKEY("readnew")}, servcmd_readnew },
1299 { {HKEY("readold")}, servcmd_readold },
1300 { {HKEY("readgt")}, servcmd_readgt },
1301 { {HKEY("readlt")}, servcmd_readlt }
1305 int ParseMessageListHeaders_Detail(StrBuf *Line,
1307 message_summary *Msg,
1308 StrBuf *ConversionBuffer)
1310 wcsession *WCC = WC;
1314 CheckConvertBufs(WCC);
1316 totallen = StrLength(Line);
1317 Msg->from = NewStrBufPlain(NULL, totallen);
1318 len = StrBufExtract_NextToken(ConversionBuffer, Line, pos, '|');
1320 /* Handle senders with RFC2047 encoding */
1321 StrBuf_RFC822_2_Utf8(Msg->from,
1323 WCC->DefaultCharset,
1330 len = StrBufExtract_NextToken(ConversionBuffer, Line, pos, '|');
1332 ( ((WCC->CurRoom.QRFlags & QR_NETWORK)
1333 || ((strcasecmp(ChrPtr(ConversionBuffer), ChrPtr(WCC->serv_info->serv_nodename))
1334 && (strcasecmp(ChrPtr(ConversionBuffer), ChrPtr(WCC->serv_info->serv_fqdn))))))))
1336 StrBufAppendBufPlain(Msg->from, HKEY(" @ "), 0);
1337 StrBufAppendBuf(Msg->from, ConversionBuffer, 0);
1340 /* Internet address (not used)
1341 * StrBufExtract_token(Msg->inetaddr, Line, 4, '|');
1343 StrBufSkip_NTokenS(Line, pos, '|', 1);
1344 Msg->subj = NewStrBufPlain(NULL, totallen);
1346 FlushStrBuf(ConversionBuffer);
1347 /* we assume the subject is the last parameter inside of the list;
1348 * thus we don't use the tokenizer to fetch it, since it will hick up
1349 * on tokenizer chars inside of the subjects
1350 StrBufExtract_NextToken(ConversionBuffer, Line, pos, '|');
1353 if (*pos != StrBufNOTNULL) {
1354 len = totallen - (*pos - ChrPtr(Line));
1355 StrBufPlain(ConversionBuffer, *pos, len);
1356 *pos = StrBufNOTNULL;
1358 (*(ChrPtr(ConversionBuffer) + len - 1) == '|'))
1359 StrBufCutRight(ConversionBuffer, 1);
1363 StrBufAppendBufPlain(Msg->subj, _("(no subject)"), -1,0);
1365 StrBuf_RFC822_2_Utf8(Msg->subj,
1367 WCC->DefaultCharset,
1377 int mailview_GetParamsGetServerCall(SharedMessageStatus *Stat,
1378 void **ViewSpecific,
1385 DoTemplate(HKEY("msg_listview"),NULL,&NoCtx);
1390 int mailview_Cleanup(void **ViewSpecific)
1392 /* Note: wDumpContent() will output one additional </div> tag. */
1393 /* We ought to move this out into template */
1400 int json_GetParamsGetServerCall(SharedMessageStatus *Stat,
1401 void **ViewSpecific,
1408 Stat->defaultsortorder = 2;
1410 Stat->load_seen = 1;
1411 /* Generally using maxmsgs|startmsg is not required
1412 in mailbox view, but we have a 'safemode' for clients
1413 (*cough* Exploder) that simply can't handle too many */
1414 if (havebstr("maxmsgs")) Stat->maxmsgs = ibstr("maxmsgs");
1415 else Stat->maxmsgs = 9999999;
1416 if (havebstr("startmsg")) Stat->startmsg = lbstr("startmsg");
1417 snprintf(cmd, len, "MSGS %s|%s||1",
1418 (oper == do_search) ? "SEARCH" : "ALL",
1419 (oper == do_search) ? bstr("query") : ""
1424 int json_MessageListHdr(SharedMessageStatus *Stat, void **ViewSpecific)
1426 /* TODO: make a generic function */
1427 hprintf("HTTP/1.1 200 OK\r\n");
1428 hprintf("Content-type: application/json; charset=utf-8\r\n");
1429 hprintf("Server: %s / %s\r\n", PACKAGE_STRING, ChrPtr(WC->serv_info->serv_software));
1430 hprintf("Connection: close\r\n");
1431 hprintf("Pragma: no-cache\r\nCache-Control: no-store\r\nExpires:-1\r\n");
1436 int json_RenderView_or_Tail(SharedMessageStatus *Stat,
1437 void **ViewSpecific,
1440 DoTemplate(HKEY("mailsummary_json"),NULL, NULL);
1445 int json_Cleanup(void **ViewSpecific)
1447 /* Note: wDumpContent() will output one additional </div> tag. */
1448 /* We ought to move this out into template */
1457 InitModule_MSGRENDERERS
1460 RegisterCTX(CTX_MAILSUM);
1461 RegisterCTX(CTX_MIME_ATACH);
1462 RegisterReadLoopHandlerset(
1464 mailview_GetParamsGetServerCall,
1465 NULL, /* TODO: is this right? */
1467 ParseMessageListHeaders_Detail,
1472 RegisterReadLoopHandlerset(
1474 json_GetParamsGetServerCall,
1475 json_MessageListHdr,
1476 NULL, /* TODO: is this right? */
1477 ParseMessageListHeaders_Detail,
1479 json_RenderView_or_Tail,
1482 RegisterSortFunc(HKEY("date"),
1488 RegisterSortFunc(HKEY("subject"),
1494 RegisterSortFunc(HKEY("sender"),
1501 RegisterNamespace("SUMM:COUNT", 0, 0, tmplput_SUMM_COUNT, NULL, CTX_NONE);
1502 /* iterate over all known mails in WC->summ */
1503 RegisterIterator("MAIL:SUMM:MSGS", 0, NULL, iterate_get_mailsumm_All,
1504 NULL,NULL, CTX_MAILSUM, CTX_NONE, IT_NOFLAG);
1506 RegisterNamespace("MAIL:SUMM:EUID", 0, 1, tmplput_MAIL_SUMM_EUID, NULL, CTX_MAILSUM);
1507 RegisterNamespace("MAIL:SUMM:DATEBRIEF", 0, 0, tmplput_MAIL_SUMM_DATE_BRIEF, NULL, CTX_MAILSUM);
1508 RegisterNamespace("MAIL:SUMM:DATEFULL", 0, 0, tmplput_MAIL_SUMM_DATE_FULL, NULL, CTX_MAILSUM);
1509 RegisterNamespace("MAIL:SUMM:DATENO", 0, 0, tmplput_MAIL_SUMM_DATE_NO, NULL, CTX_MAILSUM);
1510 RegisterNamespace("MAIL:SUMM:N", 0, 0, tmplput_MAIL_SUMM_N, NULL, CTX_MAILSUM);
1511 RegisterNamespace("MAIL:SUMM:PERMALINK", 0, 0, tmplput_MAIL_SUMM_PERMALINK, NULL, CTX_MAILSUM);
1512 RegisterNamespace("MAIL:SUMM:FROM", 0, 2, tmplput_MAIL_SUMM_FROM, NULL, CTX_MAILSUM);
1513 RegisterNamespace("MAIL:SUMM:TO", 0, 2, tmplput_MAIL_SUMM_TO, NULL, CTX_MAILSUM);
1514 RegisterNamespace("MAIL:SUMM:SUBJECT", 0, 4, tmplput_MAIL_SUMM_SUBJECT, NULL, CTX_MAILSUM);
1515 RegisterNamespace("MAIL:SUMM:NTATACH", 0, 0, tmplput_MAIL_SUMM_NATTACH, NULL, CTX_MAILSUM);
1516 RegisterNamespace("MAIL:SUMM:CCCC", 0, 2, tmplput_MAIL_SUMM_CCCC, NULL, CTX_MAILSUM);
1517 RegisterNamespace("MAIL:SUMM:REPLYTO", 0, 2, tmplput_MAIL_SUMM_REPLYTO, NULL, CTX_MAILSUM);
1518 RegisterNamespace("MAIL:SUMM:H_NODE", 0, 2, tmplput_MAIL_SUMM_H_NODE, NULL, CTX_MAILSUM);
1519 RegisterNamespace("MAIL:SUMM:ALLRCPT", 0, 2, tmplput_MAIL_SUMM_ALLRCPT, NULL, CTX_MAILSUM);
1520 RegisterNamespace("MAIL:SUMM:ORGROOM", 0, 2, tmplput_MAIL_SUMM_ORGROOM, NULL, CTX_MAILSUM);
1521 RegisterNamespace("MAIL:SUMM:RFCA", 0, 2, tmplput_MAIL_SUMM_RFCA, NULL, CTX_MAILSUM);
1522 RegisterNamespace("MAIL:SUMM:OTHERNODE", 2, 0, tmplput_MAIL_SUMM_OTHERNODE, NULL, CTX_MAILSUM);
1523 RegisterNamespace("MAIL:SUMM:REFIDS", 0, 1, tmplput_MAIL_SUMM_REFIDS, NULL, CTX_MAILSUM);
1524 RegisterNamespace("MAIL:SUMM:INREPLYTO", 0, 2, tmplput_MAIL_SUMM_INREPLYTO, NULL, CTX_MAILSUM);
1525 RegisterNamespace("MAIL:BODY", 0, 2, tmplput_MAIL_BODY, NULL, CTX_MAILSUM);
1526 RegisterNamespace("MAIL:QUOTETEXT", 1, 2, tmplput_QUOTED_MAIL_BODY, NULL, CTX_NONE);
1527 RegisterNamespace("MAIL:EDITTEXT", 1, 2, tmplput_EDIT_MAIL_BODY, NULL, CTX_NONE);
1528 RegisterNamespace("MAIL:EDITWIKI", 1, 2, tmplput_EDIT_WIKI_BODY, NULL, CTX_NONE);
1529 RegisterConditional("COND:MAIL:SUMM:RFCA", 0, Conditional_MAIL_SUMM_RFCA, CTX_MAILSUM);
1530 RegisterConditional("COND:MAIL:SUMM:CCCC", 0, Conditional_MAIL_SUMM_CCCC, CTX_MAILSUM);
1531 RegisterConditional("COND:MAIL:SUMM:REPLYTO", 0, Conditional_MAIL_SUMM_REPLYTO, CTX_MAILSUM);
1532 RegisterConditional("COND:MAIL:SUMM:UNREAD", 0, Conditional_MAIL_SUMM_UNREAD, CTX_MAILSUM);
1533 RegisterConditional("COND:MAIL:SUMM:H_NODE", 0, Conditional_MAIL_SUMM_H_NODE, CTX_MAILSUM);
1534 RegisterConditional("COND:MAIL:SUMM:OTHERNODE", 0, Conditional_MAIL_SUMM_OTHERNODE, CTX_MAILSUM);
1535 RegisterConditional("COND:MAIL:SUMM:SUBJECT", 0, Conditional_MAIL_SUMM_SUBJECT, CTX_MAILSUM);
1536 RegisterConditional("COND:MAIL:ANON", 0, Conditional_ANONYMOUS_MESSAGE, CTX_MAILSUM);
1537 RegisterConditional("COND:MAIL:TO", 0, Conditional_MAIL_SUMM_TO, CTX_MAILSUM);
1538 RegisterConditional("COND:MAIL:SUBJ", 0, Conditional_MAIL_SUMM_SUBJ, CTX_MAILSUM);
1540 /* do we have mimetypes to iterate over? */
1541 RegisterConditional("COND:MAIL:MIME:ATTACH", 0, Conditional_MAIL_MIME_ALL, CTX_MAILSUM);
1542 RegisterConditional("COND:MAIL:MIME:ATTACH:SUBMESSAGES", 0, Conditional_MAIL_MIME_SUBMESSAGES, CTX_MAILSUM);
1543 RegisterConditional("COND:MAIL:MIME:ATTACH:LINKS", 0, Conditional_MAIL_MIME_ATTACHLINKS, CTX_MAILSUM);
1544 RegisterConditional("COND:MAIL:MIME:ATTACH:ATT", 0, Conditional_MAIL_MIME_ATTACH, CTX_MAILSUM);
1545 RegisterIterator("MAIL:MIME:ATTACH", 0, NULL, iterate_get_mime_All,
1546 NULL, NULL, CTX_MIME_ATACH, CTX_MAILSUM, IT_NOFLAG);
1547 RegisterIterator("MAIL:MIME:ATTACH:SUBMESSAGES", 0, NULL, iterate_get_mime_Submessages,
1548 NULL, NULL, CTX_MIME_ATACH, CTX_MAILSUM, IT_NOFLAG);
1549 RegisterIterator("MAIL:MIME:ATTACH:LINKS", 0, NULL, iterate_get_mime_AttachLinks,
1550 NULL, NULL, CTX_MIME_ATACH, CTX_MAILSUM, IT_NOFLAG);
1551 RegisterIterator("MAIL:MIME:ATTACH:ATT", 0, NULL, iterate_get_mime_Attachments,
1552 NULL, NULL, CTX_MIME_ATACH, CTX_MAILSUM, IT_NOFLAG);
1554 /* Parts of a mime attachent */
1555 RegisterNamespace("MAIL:MIME:NAME", 0, 2, tmplput_MIME_Name, NULL, CTX_MIME_ATACH);
1556 RegisterNamespace("MAIL:MIME:FILENAME", 0, 2, tmplput_MIME_FileName, NULL, CTX_MIME_ATACH);
1557 RegisterNamespace("MAIL:MIME:PARTNUM", 0, 2, tmplput_MIME_PartNum, NULL, CTX_MIME_ATACH);
1558 RegisterNamespace("MAIL:MIME:MSGNUM", 0, 2, tmplput_MIME_MsgNum, NULL, CTX_MIME_ATACH);
1559 RegisterNamespace("MAIL:MIME:DISPOSITION", 0, 2, tmplput_MIME_Disposition, NULL, CTX_MIME_ATACH);
1560 RegisterNamespace("MAIL:MIME:CONTENTTYPE", 0, 2, tmplput_MIME_ContentType, NULL, CTX_MIME_ATACH);
1561 RegisterNamespace("MAIL:MIME:CHARSET", 0, 2, tmplput_MIME_Charset, NULL, CTX_MIME_ATACH);
1562 RegisterNamespace("MAIL:MIME:LENGTH", 0, 2, tmplput_MIME_Length, NULL, CTX_MIME_ATACH);
1563 RegisterNamespace("MAIL:MIME:DATA", 0, 2, tmplput_MIME_Data, NULL, CTX_MIME_ATACH);
1564 /* load the actual attachment into WC->attachments; no output!!! */
1565 RegisterNamespace("MAIL:MIME:LOADDATA", 0, 0, tmplput_MIME_LoadData, NULL, CTX_MIME_ATACH);
1567 /* iterate the WC->attachments; use the above tokens for their contents */
1568 RegisterIterator("MSG:ATTACHNAMES", 0, NULL, iterate_get_registered_Attachments,
1569 NULL, NULL, CTX_MIME_ATACH, CTX_NONE, IT_NOFLAG);
1571 RegisterNamespace("MSG:NATTACH", 0, 0, get_registered_Attachments_Count, NULL, CTX_NONE);
1573 /* mime renderers translate an attachment into webcit viewable html text */
1574 RegisterMimeRenderer(HKEY("message/rfc822"), render_MAIL, 0, 150);
1575 RegisterMimeRenderer(HKEY("text/x-vcard"), render_MIME_VCard, 1, 201);
1576 RegisterMimeRenderer(HKEY("text/vcard"), render_MIME_VCard, 1, 200);
1578 RegisterMimeRenderer(HKEY("text/calendar"), render_MIME_ICS, 1, 501);
1579 RegisterMimeRenderer(HKEY("application/ics"), render_MIME_ICS, 1, 500);
1581 RegisterMimeRenderer(HKEY("text/x-citadel-variformat"), render_MAIL_variformat, 1, 2);
1582 RegisterMimeRenderer(HKEY("text/plain"), render_MAIL_text_plain, 1, 3);
1583 RegisterMimeRenderer(HKEY("text"), render_MAIL_text_plain, 1, 1);
1584 RegisterMimeRenderer(HKEY("text/html"), render_MAIL_html, 1, 100);
1585 RegisterMimeRenderer(HKEY(""), render_MAIL_UNKNOWN, 0, 0);
1587 /* these headers are citserver replies to MSG4 and friends. one evaluator for each */
1588 RegisterMsgHdr(HKEY("nhdr"), examine_nhdr, 0);
1589 RegisterMsgHdr(HKEY("type"), examine_type, 0);
1590 RegisterMsgHdr(HKEY("from"), examine_from, 0);
1591 RegisterMsgHdr(HKEY("subj"), examine_subj, 0);
1592 RegisterMsgHdr(HKEY("msgn"), examine_msgn, 0);
1593 RegisterMsgHdr(HKEY("wefw"), examine_wefw, 0);
1594 RegisterMsgHdr(HKEY("cccc"), examine_cccc, 0);
1595 RegisterMsgHdr(HKEY("rep2"), examine_replyto, 0);
1596 RegisterMsgHdr(HKEY("hnod"), examine_hnod, 0);
1597 RegisterMsgHdr(HKEY("room"), examine_room, 0);
1598 RegisterMsgHdr(HKEY("rfca"), examine_rfca, 0);
1599 RegisterMsgHdr(HKEY("node"), examine_node, 0);
1600 RegisterMsgHdr(HKEY("rcpt"), examine_rcpt, 0);
1601 RegisterMsgHdr(HKEY("time"), examine_time, 0);
1602 RegisterMsgHdr(HKEY("part"), examine_mime_part, 0);
1603 RegisterMsgHdr(HKEY("text"), examine_text, 1);
1604 /* these are the content-type headers we get infront of a message; put it into the same hash since it doesn't clash. */
1605 RegisterMsgHdr(HKEY("X-Citadel-MSG4-Partnum"), examine_msg4_partnum, 0);
1606 RegisterMsgHdr(HKEY("Content-type"), examine_content_type, 0);
1607 RegisterMsgHdr(HKEY("Content-length"), examine_content_lengh, 0);
1608 RegisterMsgHdr(HKEY("Content-transfer-encoding"), examine_content_encoding, 0); /* do we care? */
1609 RegisterMsgHdr(HKEY("charset"), examine_charset, 0);
1611 /* Don't care about these... */
1612 RegisterMsgHdr(HKEY("pref"), examine_pref, 0);
1613 RegisterMsgHdr(HKEY("suff"), examine_suff, 0);
1614 RegisterMsgHdr(HKEY("path"), examine_path, 0);
1618 InitModule2_MSGRENDERERS
1621 /* and finalize the anouncement to the server... */
1625 ServerStartModule_MSGRENDERERS
1628 MsgHeaderHandler = NewHash(1, NULL);
1629 MimeRenderHandler = NewHash(1, NULL);
1630 ReadLoopHandler = NewHash(1, NULL);
1634 ServerShutdownModule_MSGRENDERERS
1637 DeleteHash(&MsgHeaderHandler);
1638 DeleteHash(&MimeRenderHandler);
1639 DeleteHash(&ReadLoopHandler);
1645 SessionDestroyModule_MSGRENDERERS
1648 DeleteHash(&sess->attachments);
1649 FreeStrBuf(&sess->ConvertBuf1);
1650 FreeStrBuf(&sess->ConvertBuf2);