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->EnvTo);
55 FreeStrBuf(&Msg->OtherNode);
57 DeleteHash(&Msg->Attachments); /* list of Attachments */
58 DeleteHash(&Msg->Submessages);
59 DeleteHash(&Msg->AttachLinks);
60 DeleteHash(&Msg->AllAttach);
66 void RegisterMsgHdr(const char *HeaderName, long HdrNLen, ExamineMsgHeaderFunc evaluator, int type)
69 ev = (headereval*) malloc(sizeof(headereval));
70 ev->evaluator = evaluator;
72 Put(MsgHeaderHandler, HeaderName, HdrNLen, ev, NULL);
75 void RegisterMimeRenderer(const char *HeaderName, long HdrNLen,
76 RenderMimeFunc MimeRenderer,
80 RenderMimeFuncStruct *f;
82 f = (RenderMimeFuncStruct*) malloc(sizeof(RenderMimeFuncStruct));
84 Put(MimeRenderHandler, HeaderName, HdrNLen, f, NULL);
86 RegisterEmbeddableMimeType(HeaderName, HdrNLen, 10000 - Priority);
89 /*----------------------------------------------------------------------------*/
92 * comparator for two longs in descending order.
94 int longcmp_r(const void *s1, const void *s2) {
98 l1 = *(long *)GetSearchPayload(s1);
99 l2 = *(long *)GetSearchPayload(s2);
101 if (l1 > l2) return(-1);
102 if (l1 < l2) return(+1);
107 * comparator for longs; descending order.
109 int qlongcmp_r(const void *s1, const void *s2) {
113 if (l1 > l2) return(-1);
114 if (l1 < l2) return(+1);
120 * comparator for message summary structs by ascending subject.
122 int summcmp_subj(const void *s1, const void *s2) {
123 message_summary *summ1;
124 message_summary *summ2;
126 summ1 = (message_summary *)GetSearchPayload(s1);
127 summ2 = (message_summary *)GetSearchPayload(s2);
128 return strcasecmp(ChrPtr(summ1->subj), ChrPtr(summ2->subj));
132 * comparator for message summary structs by descending subject.
134 int summcmp_rsubj(const void *s1, const void *s2) {
135 message_summary *summ1;
136 message_summary *summ2;
138 summ1 = (message_summary *)GetSearchPayload(s1);
139 summ2 = (message_summary *)GetSearchPayload(s2);
140 return strcasecmp(ChrPtr(summ2->subj), ChrPtr(summ1->subj));
143 * comparator for message summary structs by descending subject.
145 int groupchange_subj(const void *s1, const void *s2) {
146 message_summary *summ1;
147 message_summary *summ2;
149 summ1 = (message_summary *)s1;
150 summ2 = (message_summary *)s2;
151 return ChrPtr(summ2->subj)[0] != ChrPtr(summ1->subj)[0];
155 * comparator for message summary structs by ascending sender.
157 int summcmp_sender(const void *s1, const void *s2) {
158 message_summary *summ1;
159 message_summary *summ2;
161 summ1 = (message_summary *)GetSearchPayload(s1);
162 summ2 = (message_summary *)GetSearchPayload(s2);
163 return strcasecmp(ChrPtr(summ1->from), ChrPtr(summ2->from));
167 * comparator for message summary structs by descending sender.
169 int summcmp_rsender(const void *s1, const void *s2) {
170 message_summary *summ1;
171 message_summary *summ2;
173 summ1 = (message_summary *)GetSearchPayload(s1);
174 summ2 = (message_summary *)GetSearchPayload(s2);
175 return strcasecmp(ChrPtr(summ2->from), ChrPtr(summ1->from));
178 * comparator for message summary structs by descending sender.
180 int groupchange_sender(const void *s1, const void *s2) {
181 message_summary *summ1;
182 message_summary *summ2;
184 summ1 = (message_summary *)s1;
185 summ2 = (message_summary *)s2;
186 return strcasecmp(ChrPtr(summ2->from), ChrPtr(summ1->from)) != 0;
191 * comparator for message summary structs by ascending date.
193 int summcmp_date(const void *s1, const void *s2) {
194 message_summary *summ1;
195 message_summary *summ2;
197 summ1 = (message_summary *)GetSearchPayload(s1);
198 summ2 = (message_summary *)GetSearchPayload(s2);
200 if (summ1->date < summ2->date) return -1;
201 else if (summ1->date > summ2->date) return +1;
206 * comparator for message summary structs by descending date.
208 int summcmp_rdate(const void *s1, const void *s2) {
209 message_summary *summ1;
210 message_summary *summ2;
212 summ1 = (message_summary *)GetSearchPayload(s1);
213 summ2 = (message_summary *)GetSearchPayload(s2);
215 if (summ1->date < summ2->date) return +1;
216 else if (summ1->date > summ2->date) return -1;
221 * comparator for message summary structs by descending date.
223 const long DAYSECONDS = 24 * 60 * 60;
224 int groupchange_date(const void *s1, const void *s2) {
225 message_summary *summ1;
226 message_summary *summ2;
228 summ1 = (message_summary *)s1;
229 summ2 = (message_summary *)s2;
231 return (summ1->date % DAYSECONDS) != (summ2->date %DAYSECONDS);
235 /*----------------------------------------------------------------------------*/
236 /* Don't wanna know... or? */
237 void examine_pref(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset) {return;}
238 void examine_suff(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset) {return;}
239 void examine_path(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset) {return;}
240 void examine_content_encoding(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
242 /* TODO: do we care? */
245 void examine_nhdr(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
248 if (!strncasecmp(ChrPtr(HdrLine), "yes", 8))
251 int Conditional_ANONYMOUS_MESSAGE(StrBuf *Target, WCTemplputParams *TP)
253 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
254 return Msg->nhdr != 0;
257 void examine_type(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
259 Msg->format_type = StrToi(HdrLine);
263 void examine_from(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
267 CheckConvertBufs(WCC);
268 FreeStrBuf(&Msg->from);
269 Msg->from = NewStrBufPlain(NULL, StrLength(HdrLine));
270 StrBuf_RFC822_2_Utf8(Msg->from,
277 void tmplput_MAIL_SUMM_FROM(StrBuf *Target, WCTemplputParams *TP)
279 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
280 StrBufAppendTemplate(Target, TP, Msg->from, 0);
283 void examine_subj(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
287 CheckConvertBufs(WCC);
288 FreeStrBuf(&Msg->subj);
289 Msg->subj = NewStrBufPlain(NULL, StrLength(HdrLine));
290 StrBuf_RFC822_2_Utf8(Msg->subj,
297 void tmplput_MAIL_SUMM_SUBJECT(StrBuf *Target, WCTemplputParams *TP)
299 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
301 if (TP->Tokens->nParameters == 4)
306 GetTemplateTokenString(Target, TP, 3, &pch, &len);
308 (strstr(ChrPtr(Msg->subj), pch) == NULL))
310 GetTemplateTokenString(Target, TP, 2, &pch, &len);
311 StrBufAppendBufPlain(Target, pch, len, 0);
314 StrBufAppendTemplate(Target, TP, Msg->subj, 0);
316 int Conditional_MAIL_SUMM_SUBJECT(StrBuf *Target, WCTemplputParams *TP)
318 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
321 return StrLength(Msg->subj) > 0;
325 void examine_msgn(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
329 CheckConvertBufs(WCC);
330 FreeStrBuf(&Msg->reply_inreplyto);
331 Msg->reply_inreplyto = NewStrBufPlain(NULL, StrLength(HdrLine));
332 StrBuf_RFC822_2_Utf8(Msg->reply_inreplyto,
339 void tmplput_MAIL_SUMM_INREPLYTO(StrBuf *Target, WCTemplputParams *TP)
341 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
342 StrBufAppendTemplate(Target, TP, Msg->reply_inreplyto, 0);
345 int Conditional_MAIL_SUMM_UNREAD(StrBuf *Target, WCTemplputParams *TP)
347 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
348 return (Msg->Flags & MSGFLAG_READ) != 0;
351 void examine_wefw(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
355 CheckConvertBufs(WCC);
356 FreeStrBuf(&Msg->reply_references);
357 Msg->reply_references = NewStrBufPlain(NULL, StrLength(HdrLine));
358 StrBuf_RFC822_2_Utf8(Msg->reply_references,
365 void tmplput_MAIL_SUMM_REFIDS(StrBuf *Target, WCTemplputParams *TP)
367 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
368 StrBufAppendTemplate(Target, TP, Msg->reply_references, 0);
371 void examine_replyto(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
375 CheckConvertBufs(WCC);
376 FreeStrBuf(&Msg->ReplyTo);
377 Msg->ReplyTo = NewStrBufPlain(NULL, StrLength(HdrLine));
378 StrBuf_RFC822_2_Utf8(Msg->ReplyTo,
384 if (Msg->AllRcpt == NULL)
385 Msg->AllRcpt = NewStrBufPlain(NULL, StrLength(HdrLine));
386 if (StrLength(Msg->AllRcpt) > 0) {
387 StrBufAppendBufPlain(Msg->AllRcpt, HKEY(", "), 0);
389 StrBufAppendBuf(Msg->AllRcpt, Msg->ReplyTo, 0);
391 void tmplput_MAIL_SUMM_REPLYTO(StrBuf *Target, WCTemplputParams *TP)
393 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
394 StrBufAppendTemplate(Target, TP, Msg->ReplyTo, 0);
397 void examine_cccc(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
401 CheckConvertBufs(WCC);
402 FreeStrBuf(&Msg->cccc);
403 Msg->cccc = NewStrBufPlain(NULL, StrLength(HdrLine));
404 StrBuf_RFC822_2_Utf8(Msg->cccc,
410 if (Msg->AllRcpt == NULL)
411 Msg->AllRcpt = NewStrBufPlain(NULL, StrLength(HdrLine));
412 if (StrLength(Msg->AllRcpt) > 0) {
413 StrBufAppendBufPlain(Msg->AllRcpt, HKEY(", "), 0);
415 StrBufAppendBuf(Msg->AllRcpt, Msg->cccc, 0);
417 void tmplput_MAIL_SUMM_CCCC(StrBuf *Target, WCTemplputParams *TP)
419 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
420 StrBufAppendTemplate(Target, TP, Msg->cccc, 0);
424 void examine_room(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
426 if ((StrLength(HdrLine) > 0) &&
427 (strcasecmp(ChrPtr(HdrLine), ChrPtr(WC->CurRoom.name)))) {
428 FreeStrBuf(&Msg->Room);
429 Msg->Room = NewStrBufDup(HdrLine);
432 void tmplput_MAIL_SUMM_ORGROOM(StrBuf *Target, WCTemplputParams *TP)
434 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
435 StrBufAppendTemplate(Target, TP, Msg->Room, 0);
439 void examine_rfca(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
441 FreeStrBuf(&Msg->Rfca);
442 Msg->Rfca = NewStrBufDup(HdrLine);
444 void tmplput_MAIL_SUMM_RFCA(StrBuf *Target, WCTemplputParams *TP)
446 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
447 StrBufAppendTemplate(Target, TP, Msg->Rfca, 0);
449 int Conditional_MAIL_SUMM_RFCA(StrBuf *Target, WCTemplputParams *TP)
451 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
452 return StrLength(Msg->Rfca) > 0;
454 int Conditional_MAIL_SUMM_CCCC(StrBuf *Target, WCTemplputParams *TP)
456 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
457 return StrLength(Msg->cccc) > 0;
459 int Conditional_MAIL_SUMM_REPLYTO(StrBuf *Target, WCTemplputParams *TP)
461 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
462 return StrLength(Msg->ReplyTo) > 0;
465 void examine_node(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
469 if ( (StrLength(HdrLine) > 0) &&
470 ((WC->CurRoom.QRFlags & QR_NETWORK)
471 || ((strcasecmp(ChrPtr(HdrLine), ChrPtr(WCC->serv_info->serv_nodename))
472 && (strcasecmp(ChrPtr(HdrLine), ChrPtr(WCC->serv_info->serv_fqdn))))))) {
473 FreeStrBuf(&Msg->OtherNode);
474 Msg->OtherNode = NewStrBufDup(HdrLine);
477 void tmplput_MAIL_SUMM_OTHERNODE(StrBuf *Target, WCTemplputParams *TP)
479 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
480 StrBufAppendTemplate(Target, TP, Msg->OtherNode, 0);
482 int Conditional_MAIL_SUMM_OTHERNODE(StrBuf *Target, WCTemplputParams *TP)
484 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
485 return StrLength(Msg->OtherNode) > 0;
488 void examine_nvto(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
492 CheckConvertBufs(WCC);
493 FreeStrBuf(&Msg->EnvTo);
494 Msg->EnvTo = NewStrBufPlain(NULL, StrLength(HdrLine));
495 StrBuf_RFC822_2_Utf8(Msg->EnvTo,
504 void examine_rcpt(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
508 CheckConvertBufs(WCC);
509 FreeStrBuf(&Msg->to);
510 Msg->to = NewStrBufPlain(NULL, StrLength(HdrLine));
511 StrBuf_RFC822_2_Utf8(Msg->to,
517 if (Msg->AllRcpt == NULL)
518 Msg->AllRcpt = NewStrBufPlain(NULL, StrLength(HdrLine));
519 if (StrLength(Msg->AllRcpt) > 0) {
520 StrBufAppendBufPlain(Msg->AllRcpt, HKEY(", "), 0);
522 StrBufAppendBuf(Msg->AllRcpt, Msg->to, 0);
524 void tmplput_MAIL_SUMM_TO(StrBuf *Target, WCTemplputParams *TP)
526 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
527 StrBufAppendTemplate(Target, TP, Msg->to, 0);
529 int Conditional_MAIL_SUMM_TO(StrBuf *Target, WCTemplputParams *TP)
531 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
532 return StrLength(Msg->to) != 0;
534 int Conditional_MAIL_SUMM_SUBJ(StrBuf *Target, WCTemplputParams *TP)
536 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
537 return StrLength(Msg->subj) != 0;
539 void tmplput_MAIL_SUMM_ALLRCPT(StrBuf *Target, WCTemplputParams *TP)
541 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
542 StrBufAppendTemplate(Target, TP, Msg->AllRcpt, 0);
547 void tmplput_SUMM_COUNT(StrBuf *Target, WCTemplputParams *TP)
549 StrBufAppendPrintf(Target, "%d", GetCount( WC->summ));
552 HashList *iterate_get_mailsumm_All(StrBuf *Target, WCTemplputParams *TP)
556 void examine_time(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
558 Msg->date = StrTol(HdrLine);
561 void tmplput_MAIL_SUMM_DATE_BRIEF(StrBuf *Target, WCTemplputParams *TP)
564 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
565 webcit_fmt_date(datebuf, 64, Msg->date, DATEFMT_BRIEF);
566 StrBufAppendBufPlain(Target, datebuf, -1, 0);
569 void tmplput_MAIL_SUMM_EUID(StrBuf *Target, WCTemplputParams *TP)
571 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
572 StrBufAppendTemplate(Target, TP, Msg->euid, 0);
575 void tmplput_MAIL_SUMM_DATE_FULL(StrBuf *Target, WCTemplputParams *TP)
578 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
579 webcit_fmt_date(datebuf, 64, Msg->date, DATEFMT_FULL);
580 StrBufAppendBufPlain(Target, datebuf, -1, 0);
582 void tmplput_MAIL_SUMM_DATE_NO(StrBuf *Target, WCTemplputParams *TP)
584 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
585 StrBufAppendPrintf(Target, "%ld", Msg->date, 0);
590 void render_MAIL(StrBuf *Target, WCTemplputParams *TP, StrBuf *FoundCharset)
592 wc_mime_attachment *Mime = (wc_mime_attachment *) CTX(CTX_MIME_ATACH);
593 const StrBuf *TemplateMime;
595 if (Mime->Data == NULL)
596 Mime->Data = NewStrBufPlain(NULL, Mime->length);
598 FlushStrBuf(Mime->Data);
599 read_message(Mime->Data, HKEY("view_submessage"), Mime->msgnum, Mime->PartNum, &TemplateMime);
601 if ( (!IsEmptyStr(mime_submessages)) && (!section[0]) ) {
602 for (i=0; i<num_tokens(mime_submessages, '|'); ++i) {
603 extract_token(buf, mime_submessages, i, '|', sizeof buf);
604 / ** use printable_view to suppress buttons * /
605 wc_printf("<blockquote>");
606 read_message(Mime->msgnum, 1, ChrPtr(Mime->Section));
607 wc_printf("</blockquote>");
613 void render_MIME_VCard(StrBuf *Target, WCTemplputParams *TP, StrBuf *FoundCharset)
615 wc_mime_attachment *Mime = (wc_mime_attachment *) CTX(CTX_MIME_ATACH);
617 if (StrLength(Mime->Data) == 0)
619 if (StrLength(Mime->Data) > 0) {
622 /** If it's my vCard I can edit it */
623 if ( (!strcasecmp(ChrPtr(WCC->CurRoom.name), USERCONFIGROOM))
624 || (!strcasecmp(&(ChrPtr(WCC->CurRoom.name)[11]), USERCONFIGROOM))
625 || (WC->CurRoom.view == VIEW_ADDRESSBOOK)
627 StrBufAppendPrintf(Buf, "<a href=\"edit_vcard?msgnum=%ld?partnum=%s\">",
628 Mime->msgnum, ChrPtr(Mime->PartNum));
629 StrBufAppendPrintf(Buf, "[%s]</a>", _("edit"));
632 /* In all cases, display the full card */
633 display_vcard(Buf, Mime, 0, 1, NULL, -1);
634 FreeStrBuf(&Mime->Data);
640 void render_MIME_ICS(StrBuf *Target, WCTemplputParams *TP, StrBuf *FoundCharset)
642 wc_mime_attachment *Mime = (wc_mime_attachment *) CTX(CTX_MIME_ATACH);
643 if (StrLength(Mime->Data) == 0) {
646 if (StrLength(Mime->Data) > 0) {
647 cal_process_attachment(Mime);
653 void examine_mime_part(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
655 const char *Ptr = NULL;
656 wc_mime_attachment *Mime;
660 CheckConvertBufs(WCC);
661 Mime = (wc_mime_attachment*) malloc(sizeof(wc_mime_attachment));
662 memset(Mime, 0, sizeof(wc_mime_attachment));
663 Mime->msgnum = Msg->msgnum;
666 Mime->Name = NewStrBuf();
667 StrBufExtract_NextToken(Buf, HdrLine, &Ptr, '|');
668 StrBuf_RFC822_2_Utf8(Mime->Name,
674 StrBufTrim(Mime->Name);
676 StrBufExtract_NextToken(Buf, HdrLine, &Ptr, '|');
677 Mime->FileName = NewStrBuf();
678 StrBuf_RFC822_2_Utf8(Mime->FileName,
684 StrBufTrim(Mime->FileName);
686 Mime->PartNum = NewStrBuf();
687 StrBufExtract_NextToken(Mime->PartNum, HdrLine, &Ptr, '|');
688 StrBufTrim(Mime->PartNum);
689 if (strchr(ChrPtr(Mime->PartNum), '.') != NULL)
694 Mime->Disposition = NewStrBuf();
695 StrBufExtract_NextToken(Mime->Disposition, HdrLine, &Ptr, '|');
697 Mime->ContentType = NewStrBuf();
698 StrBufExtract_NextToken(Mime->ContentType, HdrLine, &Ptr, '|');
699 StrBufTrim(Mime->ContentType);
700 StrBufLowerCase(Mime->ContentType);
701 if (!strcmp(ChrPtr(Mime->ContentType), "application/octet-stream")) {
702 StrBufPlain(Mime->ContentType,
703 GuessMimeByFilename(SKEY(Mime->FileName)), -1);
706 Mime->length = StrBufExtractNext_int(HdrLine, &Ptr, '|');
708 StrBufSkip_NTokenS(HdrLine, &Ptr, '|', 1); /* cbid?? */
710 Mime->Charset = NewStrBuf();
711 StrBufExtract_NextToken(Mime->Charset, HdrLine, &Ptr, '|');
714 if ( (StrLength(Mime->FileName) == 0) && (StrLength(Mime->Name) > 0) ) {
715 StrBufAppendBuf(Mime->FileName, Mime->Name, 0);
718 if (StrLength(Msg->PartNum) > 0) {
720 StrBufPrintf(Buf, "%s.%s", ChrPtr(Msg->PartNum), ChrPtr(Mime->PartNum));
726 if (Msg->AllAttach == NULL)
727 Msg->AllAttach = NewHash(1,NULL);
728 Put(Msg->AllAttach, SKEY(Mime->PartNum), Mime, DestroyMime);
733 void evaluate_mime_part(StrBuf *Target, WCTemplputParams *TP)
735 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
736 wc_mime_attachment *Mime = (wc_mime_attachment *) CTX(CTX_MIME_ATACH);
739 /* just print the root-node */
740 if ((Mime->level >= 1) &&
741 GetHash(MimeRenderHandler, SKEY(Mime->ContentType), &vMimeRenderer) &&
742 vMimeRenderer != NULL)
744 Mime->Renderer = (RenderMimeFuncStruct*) vMimeRenderer;
745 if (Msg->Submessages == NULL)
746 Msg->Submessages = NewHash(1,NULL);
747 Put(Msg->Submessages, SKEY(Mime->PartNum), Mime, reference_free_handler);
749 else if ((Mime->level >= 1) &&
750 (!strcasecmp(ChrPtr(Mime->Disposition), "inline"))
751 && (!strncasecmp(ChrPtr(Mime->ContentType), "image/", 6)) ){
752 if (Msg->AttachLinks == NULL)
753 Msg->AttachLinks = NewHash(1,NULL);
754 Put(Msg->AttachLinks, SKEY(Mime->PartNum), Mime, reference_free_handler);
756 else if ((Mime->level >= 1) &&
757 (StrLength(Mime->ContentType) > 0) &&
758 ( (!strcasecmp(ChrPtr(Mime->Disposition), "attachment"))
759 || (!strcasecmp(ChrPtr(Mime->Disposition), "inline"))
760 || (!strcasecmp(ChrPtr(Mime->Disposition), ""))))
762 if (Msg->AttachLinks == NULL)
763 Msg->AttachLinks = NewHash(1,NULL);
764 Put(Msg->AttachLinks, SKEY(Mime->PartNum), Mime, reference_free_handler);
765 if ((strcasecmp(ChrPtr(Mime->ContentType), "application/octet-stream") == 0) &&
766 (StrLength(Mime->FileName) > 0)) {
767 FlushStrBuf(Mime->ContentType);
768 StrBufAppendBufPlain(Mime->ContentType,
769 GuessMimeByFilename(SKEY(Mime->FileName)),
775 void tmplput_MAIL_SUMM_NATTACH(StrBuf *Target, WCTemplputParams *TP)
777 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
778 StrBufAppendPrintf(Target, "%ld", GetCount(Msg->Attachments));
782 void examine_hnod(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
786 CheckConvertBufs(WCC);
787 FreeStrBuf(&Msg->hnod);
788 Msg->hnod = NewStrBufPlain(NULL, StrLength(HdrLine));
789 StrBuf_RFC822_2_Utf8(Msg->hnod,
796 void tmplput_MAIL_SUMM_H_NODE(StrBuf *Target, WCTemplputParams *TP)
798 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
799 StrBufAppendTemplate(Target, TP, Msg->hnod, 0);
801 int Conditional_MAIL_SUMM_H_NODE(StrBuf *Target, WCTemplputParams *TP)
803 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
804 return StrLength(Msg->hnod) > 0;
809 void examine_text(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
811 if (Msg->MsgBody->Data == NULL)
812 Msg->MsgBody->Data = NewStrBufPlain(NULL, SIZ);
814 FlushStrBuf(Msg->MsgBody->Data);
817 void examine_msg4_partnum(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
819 Msg->MsgBody->PartNum = NewStrBufDup(HdrLine);
820 StrBufTrim(Msg->MsgBody->PartNum);
823 void examine_content_lengh(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
825 Msg->MsgBody->length = StrTol(HdrLine);
826 Msg->MsgBody->size_known = 1;
829 void examine_content_type(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
839 Msg->MsgBody->ContentType = NewStrBufDup(HdrLine);
840 sem = strchr(ChrPtr(HdrLine), ';');
843 Token = NewStrBufPlain(NULL, StrLength(HdrLine));
844 Value = NewStrBufPlain(NULL, StrLength(HdrLine));
845 len = sem - ChrPtr(HdrLine);
846 StrBufCutAt(Msg->MsgBody->ContentType, len, NULL);
847 while (sem != NULL) {
848 while (isspace(*(sem + 1)))
850 StrBufCutLeft(HdrLine, sem - ChrPtr(HdrLine));
851 sem = strchr(ChrPtr(HdrLine), ';');
853 len = sem - ChrPtr(HdrLine);
855 len = StrLength(HdrLine);
858 StrBufAppendBufPlain(Token, ChrPtr(HdrLine), len, 0);
859 eq = strchr(ChrPtr(Token), '=');
861 len = eq - ChrPtr(Token);
862 StrBufAppendBufPlain(Value, eq + 1, StrLength(Token) - len - 1, 0);
863 StrBufCutAt(Token, len, NULL);
868 if (GetHash(MsgHeaderHandler, SKEY(Token), &vHdr) &&
870 Hdr = (headereval*)vHdr;
871 Hdr->evaluator(Msg, Value, FoundCharset);
873 else syslog(LOG_WARNING, "don't know how to handle content type sub-header[%s]\n", ChrPtr(Token));
880 void tmplput_MAIL_SUMM_N(StrBuf *Target, WCTemplputParams *TP)
882 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
883 StrBufAppendPrintf(Target, "%ld", Msg->msgnum);
887 void tmplput_MAIL_SUMM_PERMALINK(StrBuf *Target, WCTemplputParams *TP)
889 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
890 char perma_link[1024];
892 strcpy(perma_link, "/readfwd?go=");
893 urlesc(&perma_link[12], sizeof(perma_link) - 12, (char *)ChrPtr(WC->CurRoom.name) );
894 sprintf(&perma_link[strlen(perma_link)], "?start_reading_at=%ld#%ld", Msg->msgnum, Msg->msgnum);
895 StrBufAppendPrintf(Target, "%s", perma_link);
899 int Conditional_MAIL_MIME_ALL(StrBuf *Target, WCTemplputParams *TP)
901 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
902 return GetCount(Msg->Attachments) > 0;
905 int Conditional_MAIL_MIME_SUBMESSAGES(StrBuf *Target, WCTemplputParams *TP)
907 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
908 return GetCount(Msg->Submessages) > 0;
911 int Conditional_MAIL_MIME_ATTACHLINKS(StrBuf *Target, WCTemplputParams *TP)
913 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
914 return GetCount(Msg->AttachLinks) > 0;
917 int Conditional_MAIL_MIME_ATTACH(StrBuf *Target, WCTemplputParams *TP)
919 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
920 return GetCount(Msg->AllAttach) > 0;
923 void tmplput_QUOTED_MAIL_BODY(StrBuf *Target, WCTemplputParams *TP)
929 MsgNum = LBstr(TKEY(0));
931 read_message(Buf, HKEY("view_message_replyquote"), MsgNum, NULL, &Mime);
932 StrBufAppendTemplate(Target, TP, Buf, 1);
936 void tmplput_EDIT_MAIL_BODY(StrBuf *Target, WCTemplputParams *TP)
942 MsgNum = LBstr(TKEY(0));
944 read_message(Buf, HKEY("view_message_edit"), MsgNum, NULL, &Mime);
945 StrBufAppendTemplate(Target, TP, Buf, 1);
949 void tmplput_EDIT_WIKI_BODY(StrBuf *Target, WCTemplputParams *TP)
955 /* Insert the existing content of the wiki page into the editor. But we only want
956 * to do this the first time -- if the user is uploading an attachment we don't want
959 if (!havebstr("attach_button")) {
960 char *wikipage = strdup(bstr("page"));
961 putbstr("format", NewStrBufPlain(HKEY("plain")));
962 str_wiki_index(wikipage);
963 msgnum = locate_message_by_uid(wikipage);
967 read_message(Buf, HKEY("view_message_wikiedit"), msgnum, NULL, &Mime);
968 StrBufAppendTemplate(Target, TP, Buf, 1);
974 void tmplput_MAIL_BODY(StrBuf *Target, WCTemplputParams *TP)
976 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
977 StrBufAppendTemplate(Target, TP, Msg->MsgBody->Data, 0);
981 void render_MAIL_variformat(StrBuf *Target, WCTemplputParams *TP, StrBuf *FoundCharset)
983 /* Messages in legacy Citadel variformat get handled thusly... */
984 wc_mime_attachment *Mime = (wc_mime_attachment *) CTX(CTX_MIME_ATACH);
985 StrBuf *TTarget = NewStrBufPlain(NULL, StrLength(Mime->Data));
986 FmOut(TTarget, "JUSTIFY", Mime->Data);
987 FreeStrBuf(&Mime->Data);
988 Mime->Data = TTarget;
991 void render_MAIL_text_plain(StrBuf *Target, WCTemplputParams *TP, StrBuf *FoundCharset)
993 wc_mime_attachment *Mime = (wc_mime_attachment *) CTX(CTX_MIME_ATACH);
994 const char *ptr, *pte;
995 const char *BufPtr = NULL;
1009 iconv_t ic = (iconv_t)(-1) ;
1012 if ((StrLength(Mime->Data) == 0) && (Mime->length > 0)) {
1013 FreeStrBuf(&Mime->Data);
1019 if (StrLength(Mime->Charset) != 0)
1021 else if (StrLength(FoundCharset) > 0)
1023 else if (StrLength(WC->DefaultCharset) > 0)
1024 cs = WC->DefaultCharset;
1028 else if (!strcasecmp(ChrPtr(cs), "utf-8")) {
1031 else if (!strcasecmp(ChrPtr(cs), "us-ascii")) {
1035 ctdl_iconv_open("UTF-8", ChrPtr(cs), &ic);
1036 if (ic == (iconv_t)(-1) ) {
1037 syslog(LOG_WARNING, "%s:%d iconv_open(UTF-8, %s) failed: %s\n",
1038 __FILE__, __LINE__, ChrPtr(Mime->Charset), strerror(errno));
1043 Line = NewStrBufPlain(NULL, SIZ);
1044 Line1 = NewStrBufPlain(NULL, SIZ);
1045 Line2 = NewStrBufPlain(NULL, SIZ);
1046 TTarget = NewStrBufPlain(NULL, StrLength(Mime->Data));
1049 if (StrLength(Mime->Data) > 0)
1052 StrBufSipLine(Line, Mime->Data, &BufPtr);
1056 len = StrLength(Line);
1059 while ((ptr < pte) &&
1068 if (i > 0) StrBufCutLeft(Line, i);
1070 if (StrLength(Line) == 0) {
1073 StrBufAppendBufPlain(TTarget, HKEY("<tt></tt><br>\n"), 0);
1079 for (i = bn; i < bq; i++)
1080 StrBufAppendBufPlain(TTarget, HKEY("<blockquote>"), 0);
1081 for (i = bq; i < bn; i++)
1082 StrBufAppendBufPlain(TTarget, HKEY("</blockquote>"), 0);
1085 StrBufConvert(Line, Line1, &ic);
1088 StrBufAppendBufPlain(TTarget, HKEY("<tt>"), 0);
1089 UrlizeText(Line1, Line, Line2);
1091 StrEscAppend(TTarget, Line1, NULL, 0, 0);
1092 StrBufAppendBufPlain(TTarget, HKEY("</tt><br>\n"), 0);
1096 while ((BufPtr != StrBufNOTNULL) &&
1099 if (nEmptyLines > 0)
1100 StrBufCutRight(TTarget, nEmptyLines * (sizeof ("<tt></tt><br>\n") - 1));
1101 for (i = 0; i < bn; i++)
1102 StrBufAppendBufPlain(TTarget, HKEY("</blockquote>"), 0);
1104 StrBufAppendBufPlain(TTarget, HKEY("</i><br>"), 0);
1106 if (ic != (iconv_t)(-1) ) {
1111 FreeStrBuf(&Mime->Data);
1112 Mime->Data = TTarget;
1113 FlushStrBuf(Mime->ContentType);
1114 StrBufAppendBufPlain(Mime->ContentType, HKEY("text/html"), 0);
1115 FlushStrBuf(Mime->Charset);
1116 StrBufAppendBufPlain(Mime->Charset, HKEY("UTF-8"), 0);
1122 void render_MAIL_html(StrBuf *Target, WCTemplputParams *TP, StrBuf *FoundCharset)
1124 wc_mime_attachment *Mime = (wc_mime_attachment *) CTX(CTX_MIME_ATACH);
1127 if (StrLength(Mime->Data) == 0)
1130 Buf = NewStrBufPlain(NULL, StrLength(Mime->Data));
1132 /* HTML is fun, but we've got to strip it first */
1133 output_html(ChrPtr(Mime->Charset),
1134 (WC->CurRoom.view == VIEW_WIKI ? 1 : 0),
1137 FreeStrBuf(&Mime->Data);
1141 #ifdef HAVE_MARKDOWN
1143 char * MarkdownHandleURL(const char* SourceURL, const int len, void* something)
1148 void render_MAIL_markdown(StrBuf *Target, WCTemplputParams *TP, StrBuf *FoundCharset)
1151 wc_mime_attachment *Mime = (wc_mime_attachment *) CTX(CTX_MIME_ATACH);
1153 char *md_as_html = NULL;
1156 if (StrLength(Mime->Data) == 0)
1159 format = bstr("format");
1161 if ((format == NULL) ||
1162 strcmp(format, "plain"))
1164 doc = mkd_string(ChrPtr(Mime->Data), StrLength(Mime->Data), 0);
1165 mkd_basename(doc, "/wiki?page=");
1166 mkd_compile(doc, 0);
1167 if (mkd_document(doc, &md_as_html) != EOF) {
1168 FreeStrBuf(&Mime->Data);
1169 Mime->Data = NewStrBufPlain(md_as_html, -1);
1171 // free(md_as_html);
1177 void render_MAIL_UNKNOWN(StrBuf *Target, WCTemplputParams *TP, StrBuf *FoundCharset)
1179 wc_mime_attachment *Mime = (wc_mime_attachment *) CTX(CTX_MIME_ATACH);
1180 /* Unknown weirdness */
1181 FlushStrBuf(Mime->Data);
1182 StrBufAppendBufPlain(Mime->Data, _("I don't know how to display "), -1, 0);
1183 StrBufAppendBuf(Mime->Data, Mime->ContentType, 0);
1184 StrBufAppendBufPlain(Mime->Data, HKEY("<br>\n"), 0);
1188 HashList *iterate_get_mime_All(StrBuf *Target, WCTemplputParams *TP)
1190 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
1191 return Msg->Attachments;
1193 HashList *iterate_get_mime_Submessages(StrBuf *Target, WCTemplputParams *TP)
1195 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
1196 return Msg->Submessages;
1198 HashList *iterate_get_mime_AttachLinks(StrBuf *Target, WCTemplputParams *TP)
1200 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
1201 return Msg->AttachLinks;
1203 HashList *iterate_get_mime_Attachments(StrBuf *Target, WCTemplputParams *TP)
1205 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
1206 return Msg->AllAttach;
1209 void tmplput_MIME_Name(StrBuf *Target, WCTemplputParams *TP)
1211 wc_mime_attachment *mime = (wc_mime_attachment*) CTX(CTX_MIME_ATACH);
1212 StrBufAppendTemplate(Target, TP, mime->Name, 0);
1215 void tmplput_MIME_FileName(StrBuf *Target, WCTemplputParams *TP)
1217 wc_mime_attachment *mime = (wc_mime_attachment*) CTX(CTX_MIME_ATACH);
1218 StrBufAppendTemplate(Target, TP, mime->FileName, 0);
1221 void tmplput_MIME_PartNum(StrBuf *Target, WCTemplputParams *TP)
1223 wc_mime_attachment *mime = (wc_mime_attachment*) CTX(CTX_MIME_ATACH);
1224 StrBufAppendTemplate(Target, TP, mime->PartNum, 0);
1227 void tmplput_MIME_MsgNum(StrBuf *Target, WCTemplputParams *TP)
1229 wc_mime_attachment *mime = (wc_mime_attachment*) CTX(CTX_MIME_ATACH);
1230 StrBufAppendPrintf(Target, "%ld", mime->msgnum);
1233 void tmplput_MIME_Disposition(StrBuf *Target, WCTemplputParams *TP)
1235 wc_mime_attachment *mime = (wc_mime_attachment*) CTX(CTX_MIME_ATACH);
1236 StrBufAppendTemplate(Target, TP, mime->Disposition, 0);
1239 void tmplput_MIME_ContentType(StrBuf *Target, WCTemplputParams *TP)
1241 wc_mime_attachment *mime = (wc_mime_attachment*) CTX(CTX_MIME_ATACH);
1242 StrBufAppendTemplate(Target, TP, mime->ContentType, 0);
1245 void examine_charset(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
1247 Msg->MsgBody->Charset = NewStrBufDup(HdrLine);
1250 void tmplput_MIME_Charset(StrBuf *Target, WCTemplputParams *TP)
1252 wc_mime_attachment *mime = (wc_mime_attachment*) CTX(CTX_MIME_ATACH);
1253 StrBufAppendTemplate(Target, TP, mime->Charset, 0);
1256 void tmplput_MIME_Data(StrBuf *Target, WCTemplputParams *TP)
1258 wc_mime_attachment *mime = (wc_mime_attachment*) CTX(CTX_MIME_ATACH);
1259 if (mime->Renderer != NULL)
1260 mime->Renderer->f(Target, TP, NULL);
1261 StrBufAppendTemplate(Target, TP, mime->Data, 0);
1262 /* TODO: check whether we need to load it now? */
1265 void tmplput_MIME_LoadData(StrBuf *Target, WCTemplputParams *TP)
1267 wcsession *WCC = WC;
1268 wc_mime_attachment *mime = (wc_mime_attachment*) CTX(CTX_MIME_ATACH);
1269 wc_mime_attachment *att;
1271 if (( (!strcasecmp(ChrPtr(mime->Disposition), "inline"))||
1272 (!strcasecmp(ChrPtr(mime->Disposition), "attachment"))) &&
1273 (strcasecmp(ChrPtr(mime->ContentType), "application/ms-tnef")!=0))
1278 /* steal this mime part... */
1279 att = malloc(sizeof(wc_mime_attachment));
1280 memcpy(att, mime, sizeof(wc_mime_attachment));
1281 memset(mime, 0, sizeof(wc_mime_attachment));
1283 if (att->Data == NULL)
1286 if (WCC->attachments == NULL)
1287 WCC->attachments = NewHash(1, NULL);
1288 /* And add it to the list. */
1289 n = snprintf(N, sizeof N, "%d", GetCount(WCC->attachments) + 1);
1290 Put(WCC->attachments, N, n, att, DestroyMime);
1294 void tmplput_MIME_Length(StrBuf *Target, WCTemplputParams *TP)
1296 wc_mime_attachment *mime = (wc_mime_attachment*) CTX(CTX_MIME_ATACH);
1297 StrBufAppendPrintf(Target, "%ld", mime->length);
1300 HashList *iterate_get_registered_Attachments(StrBuf *Target, WCTemplputParams *TP)
1302 return WC->attachments;
1305 void get_registered_Attachments_Count(StrBuf *Target, WCTemplputParams *TP)
1307 StrBufAppendPrintf(Target, "%ld", GetCount (WC->attachments));
1310 void servcmd_do_search(char *buf, long bufsize)
1312 snprintf(buf, bufsize, "MSGS SEARCH|%s", bstr("query"));
1315 void servcmd_headers(char *buf, long bufsize)
1317 snprintf(buf, bufsize, "MSGS ALL");
1320 void servcmd_readfwd(char *buf, long bufsize)
1322 snprintf(buf, bufsize, "MSGS ALL");
1325 void servcmd_readgt(char *buf, long bufsize)
1327 snprintf(buf, bufsize, "MSGS GT|%s", bstr("gt"));
1330 void servcmd_readlt(char *buf, long bufsize)
1332 snprintf(buf, bufsize, "MSGS LT|%s", bstr("lt"));
1335 void servcmd_readnew(char *buf, long bufsize)
1337 snprintf(buf, bufsize, "MSGS NEW");
1340 void servcmd_readold(char *buf, long bufsize)
1342 snprintf(buf, bufsize, "MSGS OLD");
1346 /* DO NOT REORDER OR REMOVE ANY OF THESE */
1347 readloop_struct rlid[] = {
1348 { {HKEY("do_search")}, servcmd_do_search },
1349 { {HKEY("headers")}, servcmd_headers },
1350 { {HKEY("readfwd")}, servcmd_readfwd },
1351 { {HKEY("readnew")}, servcmd_readnew },
1352 { {HKEY("readold")}, servcmd_readold },
1353 { {HKEY("readgt")}, servcmd_readgt },
1354 { {HKEY("readlt")}, servcmd_readlt }
1358 int ParseMessageListHeaders_Detail(StrBuf *Line,
1360 message_summary *Msg,
1361 StrBuf *ConversionBuffer)
1363 wcsession *WCC = WC;
1367 CheckConvertBufs(WCC);
1369 totallen = StrLength(Line);
1370 Msg->from = NewStrBufPlain(NULL, totallen);
1371 len = StrBufExtract_NextToken(ConversionBuffer, Line, pos, '|');
1373 /* Handle senders with RFC2047 encoding */
1374 StrBuf_RFC822_2_Utf8(Msg->from,
1376 WCC->DefaultCharset,
1383 len = StrBufExtract_NextToken(ConversionBuffer, Line, pos, '|');
1385 ( ((WCC->CurRoom.QRFlags & QR_NETWORK)
1386 || ((strcasecmp(ChrPtr(ConversionBuffer), ChrPtr(WCC->serv_info->serv_nodename))
1387 && (strcasecmp(ChrPtr(ConversionBuffer), ChrPtr(WCC->serv_info->serv_fqdn))))))))
1389 StrBufAppendBufPlain(Msg->from, HKEY(" @ "), 0);
1390 StrBufAppendBuf(Msg->from, ConversionBuffer, 0);
1393 /* Internet address (not used)
1394 * StrBufExtract_token(Msg->inetaddr, Line, 4, '|');
1396 StrBufSkip_NTokenS(Line, pos, '|', 1);
1397 Msg->subj = NewStrBufPlain(NULL, totallen);
1399 FlushStrBuf(ConversionBuffer);
1400 /* we assume the subject is the last parameter inside of the list;
1401 * thus we don't use the tokenizer to fetch it, since it will hick up
1402 * on tokenizer chars inside of the subjects
1403 StrBufExtract_NextToken(ConversionBuffer, Line, pos, '|');
1406 if (*pos != StrBufNOTNULL) {
1407 len = totallen - (*pos - ChrPtr(Line));
1408 StrBufPlain(ConversionBuffer, *pos, len);
1409 *pos = StrBufNOTNULL;
1411 (*(ChrPtr(ConversionBuffer) + len - 1) == '|'))
1412 StrBufCutRight(ConversionBuffer, 1);
1416 StrBufAppendBufPlain(Msg->subj, _("(no subject)"), -1,0);
1418 StrBuf_RFC822_2_Utf8(Msg->subj,
1420 WCC->DefaultCharset,
1430 int mailview_GetParamsGetServerCall(SharedMessageStatus *Stat,
1431 void **ViewSpecific,
1438 DoTemplate(HKEY("msg_listview"),NULL,&NoCtx);
1443 int mailview_Cleanup(void **ViewSpecific)
1445 /* Note: wDumpContent() will output one additional </div> tag. */
1446 /* We ought to move this out into template */
1453 int json_GetParamsGetServerCall(SharedMessageStatus *Stat,
1454 void **ViewSpecific,
1461 Stat->defaultsortorder = 2;
1463 Stat->load_seen = 1;
1464 /* Generally using maxmsgs|startmsg is not required
1465 in mailbox view, but we have a 'safemode' for clients
1466 (*cough* Exploder) that simply can't handle too many */
1467 if (havebstr("maxmsgs")) Stat->maxmsgs = ibstr("maxmsgs");
1468 else Stat->maxmsgs = 9999999;
1469 if (havebstr("startmsg")) Stat->startmsg = lbstr("startmsg");
1470 snprintf(cmd, len, "MSGS %s|%s||1",
1471 (oper == do_search) ? "SEARCH" : "ALL",
1472 (oper == do_search) ? bstr("query") : ""
1477 int json_MessageListHdr(SharedMessageStatus *Stat, void **ViewSpecific)
1479 /* TODO: make a generic function */
1480 hprintf("HTTP/1.1 200 OK\r\n");
1481 hprintf("Content-type: application/json; charset=utf-8\r\n");
1482 hprintf("Server: %s / %s\r\n", PACKAGE_STRING, ChrPtr(WC->serv_info->serv_software));
1483 hprintf("Connection: close\r\n");
1484 hprintf("Pragma: no-cache\r\nCache-Control: no-store\r\nExpires:-1\r\n");
1489 int json_RenderView_or_Tail(SharedMessageStatus *Stat,
1490 void **ViewSpecific,
1493 DoTemplate(HKEY("mailsummary_json"),NULL, NULL);
1498 int json_Cleanup(void **ViewSpecific)
1500 /* Note: wDumpContent() will output one additional </div> tag. */
1501 /* We ought to move this out into template */
1510 InitModule_MSGRENDERERS
1513 RegisterCTX(CTX_MAILSUM);
1514 RegisterCTX(CTX_MIME_ATACH);
1515 RegisterReadLoopHandlerset(
1517 mailview_GetParamsGetServerCall,
1518 NULL, /* TODO: is this right? */
1520 ParseMessageListHeaders_Detail,
1525 RegisterReadLoopHandlerset(
1527 json_GetParamsGetServerCall,
1528 json_MessageListHdr,
1529 NULL, /* TODO: is this right? */
1530 ParseMessageListHeaders_Detail,
1532 json_RenderView_or_Tail,
1535 RegisterSortFunc(HKEY("date"),
1541 RegisterSortFunc(HKEY("subject"),
1547 RegisterSortFunc(HKEY("sender"),
1554 RegisterNamespace("SUMM:COUNT", 0, 0, tmplput_SUMM_COUNT, NULL, CTX_NONE);
1555 /* iterate over all known mails in WC->summ */
1556 RegisterIterator("MAIL:SUMM:MSGS", 0, NULL, iterate_get_mailsumm_All,
1557 NULL,NULL, CTX_MAILSUM, CTX_NONE, IT_NOFLAG);
1559 RegisterNamespace("MAIL:SUMM:EUID", 0, 1, tmplput_MAIL_SUMM_EUID, NULL, CTX_MAILSUM);
1560 RegisterNamespace("MAIL:SUMM:DATEBRIEF", 0, 0, tmplput_MAIL_SUMM_DATE_BRIEF, NULL, CTX_MAILSUM);
1561 RegisterNamespace("MAIL:SUMM:DATEFULL", 0, 0, tmplput_MAIL_SUMM_DATE_FULL, NULL, CTX_MAILSUM);
1562 RegisterNamespace("MAIL:SUMM:DATENO", 0, 0, tmplput_MAIL_SUMM_DATE_NO, NULL, CTX_MAILSUM);
1563 RegisterNamespace("MAIL:SUMM:N", 0, 0, tmplput_MAIL_SUMM_N, NULL, CTX_MAILSUM);
1564 RegisterNamespace("MAIL:SUMM:PERMALINK", 0, 0, tmplput_MAIL_SUMM_PERMALINK, NULL, CTX_MAILSUM);
1565 RegisterNamespace("MAIL:SUMM:FROM", 0, 2, tmplput_MAIL_SUMM_FROM, NULL, CTX_MAILSUM);
1566 RegisterNamespace("MAIL:SUMM:TO", 0, 2, tmplput_MAIL_SUMM_TO, NULL, CTX_MAILSUM);
1567 RegisterNamespace("MAIL:SUMM:SUBJECT", 0, 4, tmplput_MAIL_SUMM_SUBJECT, NULL, CTX_MAILSUM);
1568 RegisterNamespace("MAIL:SUMM:NTATACH", 0, 0, tmplput_MAIL_SUMM_NATTACH, NULL, CTX_MAILSUM);
1569 RegisterNamespace("MAIL:SUMM:CCCC", 0, 2, tmplput_MAIL_SUMM_CCCC, NULL, CTX_MAILSUM);
1570 RegisterNamespace("MAIL:SUMM:REPLYTO", 0, 2, tmplput_MAIL_SUMM_REPLYTO, NULL, CTX_MAILSUM);
1571 RegisterNamespace("MAIL:SUMM:H_NODE", 0, 2, tmplput_MAIL_SUMM_H_NODE, NULL, CTX_MAILSUM);
1572 RegisterNamespace("MAIL:SUMM:ALLRCPT", 0, 2, tmplput_MAIL_SUMM_ALLRCPT, NULL, CTX_MAILSUM);
1573 RegisterNamespace("MAIL:SUMM:ORGROOM", 0, 2, tmplput_MAIL_SUMM_ORGROOM, NULL, CTX_MAILSUM);
1574 RegisterNamespace("MAIL:SUMM:RFCA", 0, 2, tmplput_MAIL_SUMM_RFCA, NULL, CTX_MAILSUM);
1575 RegisterNamespace("MAIL:SUMM:OTHERNODE", 2, 0, tmplput_MAIL_SUMM_OTHERNODE, NULL, CTX_MAILSUM);
1576 RegisterNamespace("MAIL:SUMM:REFIDS", 0, 1, tmplput_MAIL_SUMM_REFIDS, NULL, CTX_MAILSUM);
1577 RegisterNamespace("MAIL:SUMM:INREPLYTO", 0, 2, tmplput_MAIL_SUMM_INREPLYTO, NULL, CTX_MAILSUM);
1578 RegisterNamespace("MAIL:BODY", 0, 2, tmplput_MAIL_BODY, NULL, CTX_MAILSUM);
1579 RegisterNamespace("MAIL:QUOTETEXT", 1, 2, tmplput_QUOTED_MAIL_BODY, NULL, CTX_NONE);
1580 RegisterNamespace("MAIL:EDITTEXT", 1, 2, tmplput_EDIT_MAIL_BODY, NULL, CTX_NONE);
1581 RegisterNamespace("MAIL:EDITWIKI", 1, 2, tmplput_EDIT_WIKI_BODY, NULL, CTX_NONE);
1582 RegisterConditional("COND:MAIL:SUMM:RFCA", 0, Conditional_MAIL_SUMM_RFCA, CTX_MAILSUM);
1583 RegisterConditional("COND:MAIL:SUMM:CCCC", 0, Conditional_MAIL_SUMM_CCCC, CTX_MAILSUM);
1584 RegisterConditional("COND:MAIL:SUMM:REPLYTO", 0, Conditional_MAIL_SUMM_REPLYTO, CTX_MAILSUM);
1585 RegisterConditional("COND:MAIL:SUMM:UNREAD", 0, Conditional_MAIL_SUMM_UNREAD, CTX_MAILSUM);
1586 RegisterConditional("COND:MAIL:SUMM:H_NODE", 0, Conditional_MAIL_SUMM_H_NODE, CTX_MAILSUM);
1587 RegisterConditional("COND:MAIL:SUMM:OTHERNODE", 0, Conditional_MAIL_SUMM_OTHERNODE, CTX_MAILSUM);
1588 RegisterConditional("COND:MAIL:SUMM:SUBJECT", 0, Conditional_MAIL_SUMM_SUBJECT, CTX_MAILSUM);
1589 RegisterConditional("COND:MAIL:ANON", 0, Conditional_ANONYMOUS_MESSAGE, CTX_MAILSUM);
1590 RegisterConditional("COND:MAIL:TO", 0, Conditional_MAIL_SUMM_TO, CTX_MAILSUM);
1591 RegisterConditional("COND:MAIL:SUBJ", 0, Conditional_MAIL_SUMM_SUBJ, CTX_MAILSUM);
1593 /* do we have mimetypes to iterate over? */
1594 RegisterConditional("COND:MAIL:MIME:ATTACH", 0, Conditional_MAIL_MIME_ALL, CTX_MAILSUM);
1595 RegisterConditional("COND:MAIL:MIME:ATTACH:SUBMESSAGES", 0, Conditional_MAIL_MIME_SUBMESSAGES, CTX_MAILSUM);
1596 RegisterConditional("COND:MAIL:MIME:ATTACH:LINKS", 0, Conditional_MAIL_MIME_ATTACHLINKS, CTX_MAILSUM);
1597 RegisterConditional("COND:MAIL:MIME:ATTACH:ATT", 0, Conditional_MAIL_MIME_ATTACH, CTX_MAILSUM);
1598 RegisterIterator("MAIL:MIME:ATTACH", 0, NULL, iterate_get_mime_All,
1599 NULL, NULL, CTX_MIME_ATACH, CTX_MAILSUM, IT_NOFLAG);
1600 RegisterIterator("MAIL:MIME:ATTACH:SUBMESSAGES", 0, NULL, iterate_get_mime_Submessages,
1601 NULL, NULL, CTX_MIME_ATACH, CTX_MAILSUM, IT_NOFLAG);
1602 RegisterIterator("MAIL:MIME:ATTACH:LINKS", 0, NULL, iterate_get_mime_AttachLinks,
1603 NULL, NULL, CTX_MIME_ATACH, CTX_MAILSUM, IT_NOFLAG);
1604 RegisterIterator("MAIL:MIME:ATTACH:ATT", 0, NULL, iterate_get_mime_Attachments,
1605 NULL, NULL, CTX_MIME_ATACH, CTX_MAILSUM, IT_NOFLAG);
1607 /* Parts of a mime attachent */
1608 RegisterNamespace("MAIL:MIME:NAME", 0, 2, tmplput_MIME_Name, NULL, CTX_MIME_ATACH);
1609 RegisterNamespace("MAIL:MIME:FILENAME", 0, 2, tmplput_MIME_FileName, NULL, CTX_MIME_ATACH);
1610 RegisterNamespace("MAIL:MIME:PARTNUM", 0, 2, tmplput_MIME_PartNum, NULL, CTX_MIME_ATACH);
1611 RegisterNamespace("MAIL:MIME:MSGNUM", 0, 2, tmplput_MIME_MsgNum, NULL, CTX_MIME_ATACH);
1612 RegisterNamespace("MAIL:MIME:DISPOSITION", 0, 2, tmplput_MIME_Disposition, NULL, CTX_MIME_ATACH);
1613 RegisterNamespace("MAIL:MIME:CONTENTTYPE", 0, 2, tmplput_MIME_ContentType, NULL, CTX_MIME_ATACH);
1614 RegisterNamespace("MAIL:MIME:CHARSET", 0, 2, tmplput_MIME_Charset, NULL, CTX_MIME_ATACH);
1615 RegisterNamespace("MAIL:MIME:LENGTH", 0, 2, tmplput_MIME_Length, NULL, CTX_MIME_ATACH);
1616 RegisterNamespace("MAIL:MIME:DATA", 0, 2, tmplput_MIME_Data, NULL, CTX_MIME_ATACH);
1617 /* load the actual attachment into WC->attachments; no output!!! */
1618 RegisterNamespace("MAIL:MIME:LOADDATA", 0, 0, tmplput_MIME_LoadData, NULL, CTX_MIME_ATACH);
1620 /* iterate the WC->attachments; use the above tokens for their contents */
1621 RegisterIterator("MSG:ATTACHNAMES", 0, NULL, iterate_get_registered_Attachments,
1622 NULL, NULL, CTX_MIME_ATACH, CTX_NONE, IT_NOFLAG);
1624 RegisterNamespace("MSG:NATTACH", 0, 0, get_registered_Attachments_Count, NULL, CTX_NONE);
1626 /* mime renderers translate an attachment into webcit viewable html text */
1627 RegisterMimeRenderer(HKEY("message/rfc822"), render_MAIL, 0, 150);
1628 RegisterMimeRenderer(HKEY("text/x-vcard"), render_MIME_VCard, 1, 201);
1629 RegisterMimeRenderer(HKEY("text/vcard"), render_MIME_VCard, 1, 200);
1631 RegisterMimeRenderer(HKEY("text/calendar"), render_MIME_ICS, 1, 501);
1632 RegisterMimeRenderer(HKEY("application/ics"), render_MIME_ICS, 1, 500);
1634 RegisterMimeRenderer(HKEY("text/x-citadel-variformat"), render_MAIL_variformat, 1, 2);
1635 RegisterMimeRenderer(HKEY("text/plain"), render_MAIL_text_plain, 1, 3);
1636 RegisterMimeRenderer(HKEY("text"), render_MAIL_text_plain, 1, 1);
1637 RegisterMimeRenderer(HKEY("text/html"), render_MAIL_html, 1, 100);
1638 #ifdef HAVE_MARKDOWN
1639 RegisterMimeRenderer(HKEY("text/x-markdown"), render_MAIL_markdown, 1, 30);
1641 RegisterMimeRenderer(HKEY(""), render_MAIL_UNKNOWN, 0, 0);
1643 /* these headers are citserver replies to MSG4 and friends. one evaluator for each */
1644 RegisterMsgHdr(HKEY("nhdr"), examine_nhdr, 0);
1645 RegisterMsgHdr(HKEY("type"), examine_type, 0);
1646 RegisterMsgHdr(HKEY("from"), examine_from, 0);
1647 RegisterMsgHdr(HKEY("subj"), examine_subj, 0);
1648 RegisterMsgHdr(HKEY("msgn"), examine_msgn, 0);
1649 RegisterMsgHdr(HKEY("wefw"), examine_wefw, 0);
1650 RegisterMsgHdr(HKEY("cccc"), examine_cccc, 0);
1651 RegisterMsgHdr(HKEY("rep2"), examine_replyto, 0);
1652 RegisterMsgHdr(HKEY("hnod"), examine_hnod, 0);
1653 RegisterMsgHdr(HKEY("room"), examine_room, 0);
1654 RegisterMsgHdr(HKEY("rfca"), examine_rfca, 0);
1655 RegisterMsgHdr(HKEY("node"), examine_node, 0);
1656 RegisterMsgHdr(HKEY("rcpt"), examine_rcpt, 0);
1657 RegisterMsgHdr(HKEY("nvto"), examine_nvto, 0);
1658 RegisterMsgHdr(HKEY("time"), examine_time, 0);
1659 RegisterMsgHdr(HKEY("part"), examine_mime_part, 0);
1660 RegisterMsgHdr(HKEY("text"), examine_text, 1);
1661 /* these are the content-type headers we get infront of a message; put it into the same hash since it doesn't clash. */
1662 RegisterMsgHdr(HKEY("X-Citadel-MSG4-Partnum"), examine_msg4_partnum, 0);
1663 RegisterMsgHdr(HKEY("Content-type"), examine_content_type, 0);
1664 RegisterMsgHdr(HKEY("Content-length"), examine_content_lengh, 0);
1665 RegisterMsgHdr(HKEY("Content-transfer-encoding"), examine_content_encoding, 0); /* do we care? */
1666 RegisterMsgHdr(HKEY("charset"), examine_charset, 0);
1668 /* Don't care about these... */
1669 RegisterMsgHdr(HKEY("pref"), examine_pref, 0);
1670 RegisterMsgHdr(HKEY("suff"), examine_suff, 0);
1671 RegisterMsgHdr(HKEY("path"), examine_path, 0);
1675 InitModule2_MSGRENDERERS
1678 /* and finalize the anouncement to the server... */
1682 ServerStartModule_MSGRENDERERS
1685 MsgHeaderHandler = NewHash(1, NULL);
1686 MimeRenderHandler = NewHash(1, NULL);
1687 ReadLoopHandler = NewHash(1, NULL);
1691 ServerShutdownModule_MSGRENDERERS
1694 DeleteHash(&MsgHeaderHandler);
1695 DeleteHash(&MimeRenderHandler);
1696 DeleteHash(&ReadLoopHandler);
1702 SessionDestroyModule_MSGRENDERERS
1705 DeleteHash(&sess->attachments);
1706 FreeStrBuf(&sess->ConvertBuf1);
1707 FreeStrBuf(&sess->ConvertBuf2);