5 CtxType CTX_MAILSUM = CTX_NONE;
6 CtxType CTX_MIME_ATACH = CTX_NONE;
8 HashList *MsgHeaderHandler = NULL;
9 HashList *DflMsgHeaderHandler = NULL;
12 static inline void CheckConvertBufs(struct wcsession *WCC)
14 if (WCC->ConvertBuf1 == NULL)
15 WCC->ConvertBuf1 = NewStrBuf();
16 if (WCC->ConvertBuf2 == NULL)
17 WCC->ConvertBuf2 = NewStrBuf();
21 * message index functions
25 void DestroyMimeParts(wc_mime_attachment *Mime)
27 FreeStrBuf(&Mime->Name);
28 FreeStrBuf(&Mime->FileName);
29 FreeStrBuf(&Mime->PartNum);
30 FreeStrBuf(&Mime->Disposition);
31 FreeStrBuf(&Mime->ContentType);
32 FreeStrBuf(&Mime->Charset);
33 FreeStrBuf(&Mime->Data);
36 void DestroyMime(void *vMime)
38 wc_mime_attachment *Mime = (wc_mime_attachment*)vMime;
39 DestroyMimeParts(Mime);
43 void DestroyMessageSummary(void *vMsg)
45 message_summary *Msg = (message_summary*) vMsg;
47 FreeStrBuf(&Msg->from);
49 FreeStrBuf(&Msg->subj);
50 FreeStrBuf(&Msg->reply_inreplyto);
51 FreeStrBuf(&Msg->reply_references);
52 FreeStrBuf(&Msg->cccc);
53 FreeStrBuf(&Msg->ReplyTo);
54 FreeStrBuf(&Msg->hnod);
55 FreeStrBuf(&Msg->AllRcpt);
56 FreeStrBuf(&Msg->Room);
57 FreeStrBuf(&Msg->Rfca);
58 FreeStrBuf(&Msg->EnvTo);
59 FreeStrBuf(&Msg->OtherNode);
61 DeleteHash(&Msg->Attachments); /* list of Attachments */
62 DeleteHash(&Msg->Submessages);
63 DeleteHash(&Msg->AttachLinks);
64 DeleteHash(&Msg->AllAttach);
69 int EvaluateMsgHdr(const char *HeaderName, long HdrNLen, message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
72 headereval* Hdr = NULL;
74 if (GetHash(DflMsgHeaderHandler, HeaderName, HdrNLen, &vHdr) &&
76 Hdr = (headereval*)vHdr;
79 if (Hdr == NULL && GetHash(MsgHeaderHandler, HeaderName, HdrNLen, &vHdr) &&
81 Hdr = (headereval*)vHdr;
85 Hdr->evaluator(Msg, HdrLine, FoundCharset);
89 void RegisterMsgHdr(const char *HeaderName, long HdrNLen, ExamineMsgHeaderFunc evaluator, int type)
92 ev = (headereval*) malloc(sizeof(headereval));
93 ev->evaluator = evaluator;
98 if (GetFieldFromMnemonic(&f, HeaderName)) {
99 Put(DflMsgHeaderHandler, HeaderName, HdrNLen, ev, NULL);
103 Put(MsgHeaderHandler, HeaderName, HdrNLen, ev, NULL);
106 void RegisterMimeRenderer(const char *HeaderName, long HdrNLen,
107 RenderMimeFunc MimeRenderer,
108 int InlineRenderable,
111 RenderMimeFuncStruct *f;
113 f = (RenderMimeFuncStruct*) malloc(sizeof(RenderMimeFuncStruct));
115 Put(MimeRenderHandler, HeaderName, HdrNLen, f, NULL);
116 if (InlineRenderable)
117 RegisterEmbeddableMimeType(HeaderName, HdrNLen, 10000 - Priority);
120 /*----------------------------------------------------------------------------*/
123 * comparator for two longs in descending order.
125 int longcmp_r(const void *s1, const void *s2) {
129 l1 = *(long *)GetSearchPayload(s1);
130 l2 = *(long *)GetSearchPayload(s2);
132 if (l1 > l2) return(-1);
133 if (l1 < l2) return(+1);
138 * comparator for longs; descending order.
140 int qlongcmp_r(const void *s1, const void *s2) {
144 if (l1 > l2) return(-1);
145 if (l1 < l2) return(+1);
151 * comparator for message summary structs by ascending subject.
153 int summcmp_subj(const void *s1, const void *s2) {
154 message_summary *summ1;
155 message_summary *summ2;
157 summ1 = (message_summary *)GetSearchPayload(s1);
158 summ2 = (message_summary *)GetSearchPayload(s2);
159 return strcasecmp(ChrPtr(summ1->subj), ChrPtr(summ2->subj));
163 * comparator for message summary structs by descending subject.
165 int summcmp_rsubj(const void *s1, const void *s2) {
166 message_summary *summ1;
167 message_summary *summ2;
169 summ1 = (message_summary *)GetSearchPayload(s1);
170 summ2 = (message_summary *)GetSearchPayload(s2);
171 return strcasecmp(ChrPtr(summ2->subj), ChrPtr(summ1->subj));
174 * comparator for message summary structs by descending subject.
176 int groupchange_subj(const void *s1, const void *s2) {
177 message_summary *summ1;
178 message_summary *summ2;
180 summ1 = (message_summary *)s1;
181 summ2 = (message_summary *)s2;
182 return ChrPtr(summ2->subj)[0] != ChrPtr(summ1->subj)[0];
186 * comparator for message summary structs by ascending sender.
188 int summcmp_sender(const void *s1, const void *s2) {
189 message_summary *summ1;
190 message_summary *summ2;
192 summ1 = (message_summary *)GetSearchPayload(s1);
193 summ2 = (message_summary *)GetSearchPayload(s2);
194 return strcasecmp(ChrPtr(summ1->from), ChrPtr(summ2->from));
198 * comparator for message summary structs by descending sender.
200 int summcmp_rsender(const void *s1, const void *s2) {
201 message_summary *summ1;
202 message_summary *summ2;
204 summ1 = (message_summary *)GetSearchPayload(s1);
205 summ2 = (message_summary *)GetSearchPayload(s2);
206 return strcasecmp(ChrPtr(summ2->from), ChrPtr(summ1->from));
209 * comparator for message summary structs by descending sender.
211 int groupchange_sender(const void *s1, const void *s2) {
212 message_summary *summ1;
213 message_summary *summ2;
215 summ1 = (message_summary *)s1;
216 summ2 = (message_summary *)s2;
217 return strcasecmp(ChrPtr(summ2->from), ChrPtr(summ1->from)) != 0;
222 * comparator for message summary structs by ascending date.
224 int summcmp_date(const void *s1, const void *s2) {
225 message_summary *summ1;
226 message_summary *summ2;
228 summ1 = (message_summary *)GetSearchPayload(s1);
229 summ2 = (message_summary *)GetSearchPayload(s2);
231 if (summ1->date < summ2->date) return -1;
232 else if (summ1->date > summ2->date) return +1;
237 * comparator for message summary structs by descending date.
239 int summcmp_rdate(const void *s1, const void *s2) {
240 message_summary *summ1;
241 message_summary *summ2;
243 summ1 = (message_summary *)GetSearchPayload(s1);
244 summ2 = (message_summary *)GetSearchPayload(s2);
246 if (summ1->date < summ2->date) return +1;
247 else if (summ1->date > summ2->date) return -1;
252 * comparator for message summary structs by descending date.
254 const long DAYSECONDS = 24 * 60 * 60;
255 int groupchange_date(const void *s1, const void *s2) {
256 message_summary *summ1;
257 message_summary *summ2;
259 summ1 = (message_summary *)s1;
260 summ2 = (message_summary *)s2;
262 return (summ1->date % DAYSECONDS) != (summ2->date %DAYSECONDS);
266 /*----------------------------------------------------------------------------*/
267 /* Don't wanna know... or? */
268 void examine_pref(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset) {return;}
269 void examine_suff(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset) {return;}
270 void examine_path(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset) {return;}
271 void examine_content_encoding(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
273 /* TODO: do we care? */
276 void examine_nhdr(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
279 if (!strncasecmp(ChrPtr(HdrLine), "yes", 8))
282 int Conditional_ANONYMOUS_MESSAGE(StrBuf *Target, WCTemplputParams *TP)
284 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
285 return Msg->nhdr != 0;
288 void examine_type(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
290 Msg->format_type = StrToi(HdrLine);
294 void examine_from(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
298 CheckConvertBufs(WCC);
299 FreeStrBuf(&Msg->from);
300 Msg->from = NewStrBufPlain(NULL, StrLength(HdrLine));
301 StrBuf_RFC822_2_Utf8(Msg->from,
308 void tmplput_MAIL_SUMM_FROM(StrBuf *Target, WCTemplputParams *TP)
310 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
311 StrBufAppendTemplate(Target, TP, Msg->from, 0);
314 void examine_subj(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
318 CheckConvertBufs(WCC);
319 FreeStrBuf(&Msg->subj);
320 Msg->subj = NewStrBufPlain(NULL, StrLength(HdrLine));
321 StrBuf_RFC822_2_Utf8(Msg->subj,
328 void tmplput_MAIL_SUMM_SUBJECT(StrBuf *Target, WCTemplputParams *TP)
330 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
332 if (TP->Tokens->nParameters == 4)
337 GetTemplateTokenString(Target, TP, 3, &pch, &len);
339 (strstr(ChrPtr(Msg->subj), pch) == NULL))
341 GetTemplateTokenString(Target, TP, 2, &pch, &len);
342 StrBufAppendBufPlain(Target, pch, len, 0);
345 StrBufAppendTemplate(Target, TP, Msg->subj, 0);
347 int Conditional_MAIL_SUMM_SUBJECT(StrBuf *Target, WCTemplputParams *TP)
349 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
352 return StrLength(Msg->subj) > 0;
356 void examine_msgn(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
360 CheckConvertBufs(WCC);
361 FreeStrBuf(&Msg->reply_inreplyto);
362 Msg->reply_inreplyto = NewStrBufPlain(NULL, StrLength(HdrLine));
363 Msg->reply_inreplyto_hash = ThreadIdHash(HdrLine);
364 StrBuf_RFC822_2_Utf8(Msg->reply_inreplyto,
371 void tmplput_MAIL_SUMM_INREPLYTO(StrBuf *Target, WCTemplputParams *TP)
373 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
374 StrBufAppendTemplate(Target, TP, Msg->reply_inreplyto, 0);
377 int Conditional_MAIL_SUMM_UNREAD(StrBuf *Target, WCTemplputParams *TP)
379 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
380 return (Msg->Flags & MSGFLAG_READ) != 0;
383 void examine_wefw(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
387 CheckConvertBufs(WCC);
388 FreeStrBuf(&Msg->reply_references);
389 Msg->reply_references = NewStrBufPlain(NULL, StrLength(HdrLine));
390 Msg->reply_references_hash = ThreadIdHash(HdrLine);
391 StrBuf_RFC822_2_Utf8(Msg->reply_references,
398 void tmplput_MAIL_SUMM_REFIDS(StrBuf *Target, WCTemplputParams *TP)
400 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
401 StrBufAppendTemplate(Target, TP, Msg->reply_references, 0);
404 void examine_replyto(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
408 CheckConvertBufs(WCC);
409 FreeStrBuf(&Msg->ReplyTo);
410 Msg->ReplyTo = NewStrBufPlain(NULL, StrLength(HdrLine));
411 StrBuf_RFC822_2_Utf8(Msg->ReplyTo,
417 if (Msg->AllRcpt == NULL)
418 Msg->AllRcpt = NewStrBufPlain(NULL, StrLength(HdrLine));
419 if (StrLength(Msg->AllRcpt) > 0) {
420 StrBufAppendBufPlain(Msg->AllRcpt, HKEY(", "), 0);
422 StrBufAppendBuf(Msg->AllRcpt, Msg->ReplyTo, 0);
424 void tmplput_MAIL_SUMM_REPLYTO(StrBuf *Target, WCTemplputParams *TP)
426 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
427 StrBufAppendTemplate(Target, TP, Msg->ReplyTo, 0);
430 void examine_cccc(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
434 CheckConvertBufs(WCC);
435 FreeStrBuf(&Msg->cccc);
436 Msg->cccc = NewStrBufPlain(NULL, StrLength(HdrLine));
437 StrBuf_RFC822_2_Utf8(Msg->cccc,
443 if (Msg->AllRcpt == NULL)
444 Msg->AllRcpt = NewStrBufPlain(NULL, StrLength(HdrLine));
445 if (StrLength(Msg->AllRcpt) > 0) {
446 StrBufAppendBufPlain(Msg->AllRcpt, HKEY(", "), 0);
448 StrBufAppendBuf(Msg->AllRcpt, Msg->cccc, 0);
450 void tmplput_MAIL_SUMM_CCCC(StrBuf *Target, WCTemplputParams *TP)
452 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
453 StrBufAppendTemplate(Target, TP, Msg->cccc, 0);
457 void examine_room(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
459 if ((StrLength(HdrLine) > 0) &&
460 (strcasecmp(ChrPtr(HdrLine), ChrPtr(WC->CurRoom.name)))) {
461 FreeStrBuf(&Msg->Room);
462 Msg->Room = NewStrBufDup(HdrLine);
465 void tmplput_MAIL_SUMM_ORGROOM(StrBuf *Target, WCTemplputParams *TP)
467 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
468 StrBufAppendTemplate(Target, TP, Msg->Room, 0);
472 void examine_rfca(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
474 FreeStrBuf(&Msg->Rfca);
475 Msg->Rfca = NewStrBufDup(HdrLine);
477 void tmplput_MAIL_SUMM_RFCA(StrBuf *Target, WCTemplputParams *TP)
479 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
480 StrBufAppendTemplate(Target, TP, Msg->Rfca, 0);
482 int Conditional_MAIL_SUMM_RFCA(StrBuf *Target, WCTemplputParams *TP)
484 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
485 return StrLength(Msg->Rfca) > 0;
487 int Conditional_MAIL_SUMM_CCCC(StrBuf *Target, WCTemplputParams *TP)
489 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
490 return StrLength(Msg->cccc) > 0;
492 int Conditional_MAIL_SUMM_REPLYTO(StrBuf *Target, WCTemplputParams *TP)
494 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
495 return StrLength(Msg->ReplyTo) > 0;
498 void examine_node(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
502 if ( (StrLength(HdrLine) > 0) &&
503 ((WC->CurRoom.QRFlags & QR_NETWORK)
504 || ((strcasecmp(ChrPtr(HdrLine), ChrPtr(WCC->serv_info->serv_nodename))
505 && (strcasecmp(ChrPtr(HdrLine), ChrPtr(WCC->serv_info->serv_fqdn))))))) {
506 FreeStrBuf(&Msg->OtherNode);
507 Msg->OtherNode = NewStrBufDup(HdrLine);
510 void tmplput_MAIL_SUMM_OTHERNODE(StrBuf *Target, WCTemplputParams *TP)
512 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
513 StrBufAppendTemplate(Target, TP, Msg->OtherNode, 0);
515 int Conditional_MAIL_SUMM_OTHERNODE(StrBuf *Target, WCTemplputParams *TP)
517 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
518 return StrLength(Msg->OtherNode) > 0;
521 void examine_nvto(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
525 CheckConvertBufs(WCC);
526 FreeStrBuf(&Msg->EnvTo);
527 Msg->EnvTo = NewStrBufPlain(NULL, StrLength(HdrLine));
528 StrBuf_RFC822_2_Utf8(Msg->EnvTo,
537 void examine_rcpt(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
541 CheckConvertBufs(WCC);
542 FreeStrBuf(&Msg->to);
543 Msg->to = NewStrBufPlain(NULL, StrLength(HdrLine));
544 StrBuf_RFC822_2_Utf8(Msg->to,
550 if (Msg->AllRcpt == NULL)
551 Msg->AllRcpt = NewStrBufPlain(NULL, StrLength(HdrLine));
552 if (StrLength(Msg->AllRcpt) > 0) {
553 StrBufAppendBufPlain(Msg->AllRcpt, HKEY(", "), 0);
555 StrBufAppendBuf(Msg->AllRcpt, Msg->to, 0);
557 void tmplput_MAIL_SUMM_TO(StrBuf *Target, WCTemplputParams *TP)
559 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
560 StrBufAppendTemplate(Target, TP, Msg->to, 0);
562 int Conditional_MAIL_SUMM_TO(StrBuf *Target, WCTemplputParams *TP)
564 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
565 return StrLength(Msg->to) != 0;
567 int Conditional_MAIL_SUMM_SUBJ(StrBuf *Target, WCTemplputParams *TP)
569 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
570 return StrLength(Msg->subj) != 0;
572 void tmplput_MAIL_SUMM_ALLRCPT(StrBuf *Target, WCTemplputParams *TP)
574 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
575 StrBufAppendTemplate(Target, TP, Msg->AllRcpt, 0);
580 void tmplput_SUMM_COUNT(StrBuf *Target, WCTemplputParams *TP)
582 StrBufAppendPrintf(Target, "%d", GetCount( WC->summ));
585 HashList *iterate_get_mailsumm_All(StrBuf *Target, WCTemplputParams *TP)
589 void examine_time(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
591 Msg->date = StrTol(HdrLine);
594 void tmplput_MAIL_SUMM_DATE_BRIEF(StrBuf *Target, WCTemplputParams *TP)
597 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
598 webcit_fmt_date(datebuf, 64, Msg->date, DATEFMT_BRIEF);
599 StrBufAppendBufPlain(Target, datebuf, -1, 0);
602 void tmplput_MAIL_SUMM_EUID(StrBuf *Target, WCTemplputParams *TP)
604 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
605 StrBufAppendTemplate(Target, TP, Msg->euid, 0);
608 void tmplput_MAIL_SUMM_DATE_FULL(StrBuf *Target, WCTemplputParams *TP)
611 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
612 webcit_fmt_date(datebuf, 64, Msg->date, DATEFMT_FULL);
613 StrBufAppendBufPlain(Target, datebuf, -1, 0);
615 void tmplput_MAIL_SUMM_DATE_NO(StrBuf *Target, WCTemplputParams *TP)
617 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
618 StrBufAppendPrintf(Target, "%ld", Msg->date, 0);
623 void render_MAIL(StrBuf *Target, WCTemplputParams *TP, StrBuf *FoundCharset)
625 wc_mime_attachment *Mime = (wc_mime_attachment *) CTX(CTX_MIME_ATACH);
626 const StrBuf *TemplateMime;
628 if (Mime->Data == NULL)
629 Mime->Data = NewStrBufPlain(NULL, Mime->length);
631 FlushStrBuf(Mime->Data);
632 read_message(Mime->Data, HKEY("view_submessage"), Mime->msgnum, Mime->PartNum, &TemplateMime, TP);
634 if ( (!IsEmptyStr(mime_submessages)) && (!section[0]) ) {
635 for (i=0; i<num_tokens(mime_submessages, '|'); ++i) {
636 extract_token(buf, mime_submessages, i, '|', sizeof buf);
637 / ** use printable_view to suppress buttons * /
638 wc_printf("<blockquote>");
639 read_message(Mime->msgnum, 1, ChrPtr(Mime->Section));
640 wc_printf("</blockquote>");
646 void render_MIME_ICS(StrBuf *Target, WCTemplputParams *TP, StrBuf *FoundCharset)
648 wc_mime_attachment *Mime = (wc_mime_attachment *) CTX(CTX_MIME_ATACH);
649 if (StrLength(Mime->Data) == 0) {
652 if (StrLength(Mime->Data) > 0) {
653 cal_process_attachment(Mime);
659 void examine_mime_part(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
661 const char *Ptr = NULL;
662 wc_mime_attachment *Mime;
666 CheckConvertBufs(WCC);
667 Mime = (wc_mime_attachment*) malloc(sizeof(wc_mime_attachment));
668 memset(Mime, 0, sizeof(wc_mime_attachment));
669 Mime->msgnum = Msg->msgnum;
672 Mime->Name = NewStrBuf();
673 StrBufExtract_NextToken(Buf, HdrLine, &Ptr, '|');
674 StrBuf_RFC822_2_Utf8(Mime->Name,
680 StrBufTrim(Mime->Name);
682 StrBufExtract_NextToken(Buf, HdrLine, &Ptr, '|');
683 Mime->FileName = NewStrBuf();
684 StrBuf_RFC822_2_Utf8(Mime->FileName,
690 StrBufTrim(Mime->FileName);
692 Mime->PartNum = NewStrBuf();
693 StrBufExtract_NextToken(Mime->PartNum, HdrLine, &Ptr, '|');
694 StrBufTrim(Mime->PartNum);
695 if (strchr(ChrPtr(Mime->PartNum), '.') != NULL)
700 Mime->Disposition = NewStrBuf();
701 StrBufExtract_NextToken(Mime->Disposition, HdrLine, &Ptr, '|');
703 Mime->ContentType = NewStrBuf();
704 StrBufExtract_NextToken(Mime->ContentType, HdrLine, &Ptr, '|');
705 StrBufTrim(Mime->ContentType);
706 StrBufLowerCase(Mime->ContentType);
707 if (!strcmp(ChrPtr(Mime->ContentType), "application/octet-stream")) {
708 StrBufPlain(Mime->ContentType,
709 GuessMimeByFilename(SKEY(Mime->FileName)), -1);
712 Mime->length = StrBufExtractNext_int(HdrLine, &Ptr, '|');
714 StrBufSkip_NTokenS(HdrLine, &Ptr, '|', 1); /* cbid?? */
716 Mime->Charset = NewStrBuf();
717 StrBufExtract_NextToken(Mime->Charset, HdrLine, &Ptr, '|');
720 if ( (StrLength(Mime->FileName) == 0) && (StrLength(Mime->Name) > 0) ) {
721 StrBufAppendBuf(Mime->FileName, Mime->Name, 0);
724 if (StrLength(Msg->PartNum) > 0) {
726 StrBufPrintf(Buf, "%s.%s", ChrPtr(Msg->PartNum), ChrPtr(Mime->PartNum));
732 if (Msg->AllAttach == NULL)
733 Msg->AllAttach = NewHash(1,NULL);
734 Put(Msg->AllAttach, SKEY(Mime->PartNum), Mime, DestroyMime);
739 void evaluate_mime_part(StrBuf *Target, WCTemplputParams *TP)
741 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
742 wc_mime_attachment *Mime = (wc_mime_attachment *) CTX(CTX_MIME_ATACH);
745 /* just print the root-node */
746 if ((Mime->level >= 1) &&
747 GetHash(MimeRenderHandler, SKEY(Mime->ContentType), &vMimeRenderer) &&
748 vMimeRenderer != NULL)
750 Mime->Renderer = (RenderMimeFuncStruct*) vMimeRenderer;
751 if (Msg->Submessages == NULL)
752 Msg->Submessages = NewHash(1,NULL);
753 Put(Msg->Submessages, SKEY(Mime->PartNum), Mime, reference_free_handler);
755 else if ((Mime->level >= 1) &&
756 (!strcasecmp(ChrPtr(Mime->Disposition), "inline"))
757 && (!strncasecmp(ChrPtr(Mime->ContentType), "image/", 6)) ){
758 if (Msg->AttachLinks == NULL)
759 Msg->AttachLinks = NewHash(1,NULL);
760 Put(Msg->AttachLinks, SKEY(Mime->PartNum), Mime, reference_free_handler);
762 else if ((Mime->level >= 1) &&
763 (StrLength(Mime->ContentType) > 0) &&
764 ( (!strcasecmp(ChrPtr(Mime->Disposition), "attachment"))
765 || (!strcasecmp(ChrPtr(Mime->Disposition), "inline"))
766 || (!strcasecmp(ChrPtr(Mime->Disposition), ""))))
768 if (Msg->AttachLinks == NULL)
769 Msg->AttachLinks = NewHash(1,NULL);
770 Put(Msg->AttachLinks, SKEY(Mime->PartNum), Mime, reference_free_handler);
771 if ((strcasecmp(ChrPtr(Mime->ContentType), "application/octet-stream") == 0) &&
772 (StrLength(Mime->FileName) > 0)) {
773 FlushStrBuf(Mime->ContentType);
774 StrBufAppendBufPlain(Mime->ContentType,
775 GuessMimeByFilename(SKEY(Mime->FileName)),
781 void tmplput_MAIL_SUMM_NATTACH(StrBuf *Target, WCTemplputParams *TP)
783 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
784 StrBufAppendPrintf(Target, "%ld", GetCount(Msg->Attachments));
788 void examine_hnod(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
792 CheckConvertBufs(WCC);
793 FreeStrBuf(&Msg->hnod);
794 Msg->hnod = NewStrBufPlain(NULL, StrLength(HdrLine));
795 StrBuf_RFC822_2_Utf8(Msg->hnod,
802 void tmplput_MAIL_SUMM_H_NODE(StrBuf *Target, WCTemplputParams *TP)
804 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
805 StrBufAppendTemplate(Target, TP, Msg->hnod, 0);
807 int Conditional_MAIL_SUMM_H_NODE(StrBuf *Target, WCTemplputParams *TP)
809 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
810 return StrLength(Msg->hnod) > 0;
815 void examine_text(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
817 if (Msg->MsgBody->Data == NULL)
818 Msg->MsgBody->Data = NewStrBufPlain(NULL, SIZ);
820 FlushStrBuf(Msg->MsgBody->Data);
823 void examine_msg4_partnum(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
825 Msg->MsgBody->PartNum = NewStrBufDup(HdrLine);
826 StrBufTrim(Msg->MsgBody->PartNum);
829 void examine_content_lengh(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
831 Msg->MsgBody->length = StrTol(HdrLine);
832 Msg->MsgBody->size_known = 1;
835 void examine_content_type(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
843 Msg->MsgBody->ContentType = NewStrBufDup(HdrLine);
844 sem = strchr(ChrPtr(HdrLine), ';');
847 Token = NewStrBufPlain(NULL, StrLength(HdrLine));
848 Value = NewStrBufPlain(NULL, StrLength(HdrLine));
849 len = sem - ChrPtr(HdrLine);
850 StrBufCutAt(Msg->MsgBody->ContentType, len, NULL);
851 while (sem != NULL) {
852 while (isspace(*(sem + 1)))
854 StrBufCutLeft(HdrLine, sem - ChrPtr(HdrLine));
855 sem = strchr(ChrPtr(HdrLine), ';');
857 len = sem - ChrPtr(HdrLine);
859 len = StrLength(HdrLine);
862 StrBufAppendBufPlain(Token, ChrPtr(HdrLine), len, 0);
863 eq = strchr(ChrPtr(Token), '=');
865 len = eq - ChrPtr(Token);
866 StrBufAppendBufPlain(Value, eq + 1, StrLength(Token) - len - 1, 0);
867 StrBufCutAt(Token, len, NULL);
872 if (EvaluateMsgHdr(SKEY(Token), Msg, Value, FoundCharset) < 0)
873 syslog(LOG_WARNING, "don't know how to handle content type sub-header[%s]\n", ChrPtr(Token));
881 int ReadOneMessageSummary(message_summary *Msg, StrBuf *FoundCharset, StrBuf *Buf)
890 serv_printf("MSG0 %ld|1", Msg->msgnum); /* ask for headers only */
892 StrBuf_ServGetln(Buf);
893 if (GetServerStatus(Buf, NULL) != 1) {
897 while (len = StrBuf_ServGetln(Buf),
900 strcmp(ChrPtr(Buf), "000")))
903 ebuf = strchr(ChrPtr(Buf), '=');
906 if (GetHash(MsgHeaderHandler, buf, nBuf, &vHdr) &&
908 Hdr = (headereval*)vHdr;
909 StrBufCutLeft(Buf, nBuf + 1);
910 Hdr->evaluator(Msg, Buf, FoundCharset);
912 else syslog(LOG_INFO, "Don't know how to handle Message Headerline [%s]", ChrPtr(Buf));
917 void tmplput_MAIL_SUMM_N(StrBuf *Target, WCTemplputParams *TP)
919 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
920 StrBufAppendPrintf(Target, "%ld", Msg->msgnum);
924 void tmplput_MAIL_SUMM_PERMALINK(StrBuf *Target, WCTemplputParams *TP)
926 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
930 perma_link = NewStrBufPlain(HKEY("/readfwd?go="));
931 StrBufUrlescAppend(perma_link, WC->CurRoom.name, NULL);
932 View = sbstr("view");
934 StrBufAppendBufPlain(perma_link, HKEY("?view="), 0);
935 StrBufAppendBuf(perma_link, View, 0);
937 StrBufAppendBufPlain(perma_link, HKEY("?start_reading_at="), 0);
938 StrBufAppendPrintf(perma_link, "%ld#%ld", Msg->msgnum, Msg->msgnum);
939 StrBufAppendBuf(Target, perma_link, 0);
940 FreeStrBuf(&perma_link);
944 int Conditional_MAIL_MIME_ALL(StrBuf *Target, WCTemplputParams *TP)
946 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
947 return GetCount(Msg->Attachments) > 0;
950 int Conditional_MAIL_MIME_SUBMESSAGES(StrBuf *Target, WCTemplputParams *TP)
952 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
953 return GetCount(Msg->Submessages) > 0;
956 int Conditional_MAIL_MIME_ATTACHLINKS(StrBuf *Target, WCTemplputParams *TP)
958 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
959 return GetCount(Msg->AttachLinks) > 0;
962 int Conditional_MAIL_MIME_ATTACH(StrBuf *Target, WCTemplputParams *TP)
964 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
965 return GetCount(Msg->AllAttach) > 0;
968 void tmplput_QUOTED_MAIL_BODY(StrBuf *Target, WCTemplputParams *TP)
974 MsgNum = LBstr(TKEY(0));
976 read_message(Buf, HKEY("view_message_replyquote"), MsgNum, NULL, &Mime, TP);
977 StrBufAppendTemplate(Target, TP, Buf, 1);
981 void tmplput_EDIT_MAIL_BODY(StrBuf *Target, WCTemplputParams *TP)
987 MsgNum = LBstr(TKEY(0));
989 read_message(Buf, HKEY("view_message_edit"), MsgNum, NULL, &Mime, TP);
990 StrBufAppendTemplate(Target, TP, Buf, 1);
994 void tmplput_EDIT_WIKI_BODY(StrBuf *Target, WCTemplputParams *TP)
1000 /* Insert the existing content of the wiki page into the editor. But we only want
1001 * to do this the first time -- if the user is uploading an attachment we don't want
1004 if (!havebstr("attach_button")) {
1005 char *wikipage = strdup(bstr("page"));
1006 putbstr("format", NewStrBufPlain(HKEY("plain")));
1007 str_wiki_index(wikipage);
1008 msgnum = locate_message_by_uid(wikipage);
1012 read_message(Buf, HKEY("view_message_wikiedit"), msgnum, NULL, &Mime, TP);
1013 StrBufAppendTemplate(Target, TP, Buf, 1);
1019 void tmplput_MAIL_BODY(StrBuf *Target, WCTemplputParams *TP)
1021 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
1022 StrBufAppendTemplate(Target, TP, Msg->MsgBody->Data, 0);
1026 void render_MAIL_variformat(StrBuf *Target, WCTemplputParams *TP, StrBuf *FoundCharset)
1028 /* Messages in legacy Citadel variformat get handled thusly... */
1029 wc_mime_attachment *Mime = (wc_mime_attachment *) CTX(CTX_MIME_ATACH);
1030 StrBuf *TTarget = NewStrBufPlain(NULL, StrLength(Mime->Data));
1031 FmOut(TTarget, "JUSTIFY", Mime->Data);
1032 FreeStrBuf(&Mime->Data);
1033 Mime->Data = TTarget;
1036 void render_MAIL_text_plain(StrBuf *Target, WCTemplputParams *TP, StrBuf *FoundCharset)
1038 wc_mime_attachment *Mime = (wc_mime_attachment *) CTX(CTX_MIME_ATACH);
1039 const char *ptr, *pte;
1040 const char *BufPtr = NULL;
1054 iconv_t ic = (iconv_t)(-1) ;
1057 if ((StrLength(Mime->Data) == 0) && (Mime->length > 0)) {
1058 FreeStrBuf(&Mime->Data);
1064 if (StrLength(Mime->Charset) != 0)
1066 else if (StrLength(FoundCharset) > 0)
1068 else if (StrLength(WC->DefaultCharset) > 0)
1069 cs = WC->DefaultCharset;
1073 else if (!strcasecmp(ChrPtr(cs), "utf-8")) {
1076 else if (!strcasecmp(ChrPtr(cs), "us-ascii")) {
1080 ctdl_iconv_open("UTF-8", ChrPtr(cs), &ic);
1081 if (ic == (iconv_t)(-1) ) {
1082 syslog(LOG_WARNING, "%s:%d iconv_open(UTF-8, %s) failed: %s\n",
1083 __FILE__, __LINE__, ChrPtr(Mime->Charset), strerror(errno));
1088 Line = NewStrBufPlain(NULL, SIZ);
1089 Line1 = NewStrBufPlain(NULL, SIZ);
1090 Line2 = NewStrBufPlain(NULL, SIZ);
1091 TTarget = NewStrBufPlain(NULL, StrLength(Mime->Data));
1094 if (StrLength(Mime->Data) > 0)
1097 StrBufSipLine(Line, Mime->Data, &BufPtr);
1101 len = StrLength(Line);
1104 while ((ptr < pte) &&
1113 if (i > 0) StrBufCutLeft(Line, i);
1115 if (StrLength(Line) == 0) {
1118 StrBufAppendBufPlain(TTarget, HKEY("<tt></tt><br>\n"), 0);
1124 for (i = bn; i < bq; i++)
1125 StrBufAppendBufPlain(TTarget, HKEY("<blockquote>"), 0);
1126 for (i = bq; i < bn; i++)
1127 StrBufAppendBufPlain(TTarget, HKEY("</blockquote>"), 0);
1130 StrBufConvert(Line, Line1, &ic);
1133 StrBufAppendBufPlain(TTarget, HKEY("<tt>"), 0);
1134 UrlizeText(Line1, Line, Line2);
1136 StrEscAppend(TTarget, Line1, NULL, 0, 0);
1137 StrBufAppendBufPlain(TTarget, HKEY("</tt><br>\n"), 0);
1141 while ((BufPtr != StrBufNOTNULL) &&
1144 if (nEmptyLines > 0)
1145 StrBufCutRight(TTarget, nEmptyLines * (sizeof ("<tt></tt><br>\n") - 1));
1146 for (i = 0; i < bn; i++)
1147 StrBufAppendBufPlain(TTarget, HKEY("</blockquote>"), 0);
1149 StrBufAppendBufPlain(TTarget, HKEY("</i><br>"), 0);
1151 if (ic != (iconv_t)(-1) ) {
1156 FreeStrBuf(&Mime->Data);
1157 Mime->Data = TTarget;
1158 FlushStrBuf(Mime->ContentType);
1159 StrBufAppendBufPlain(Mime->ContentType, HKEY("text/html"), 0);
1160 FlushStrBuf(Mime->Charset);
1161 StrBufAppendBufPlain(Mime->Charset, HKEY("UTF-8"), 0);
1167 void render_MAIL_html(StrBuf *Target, WCTemplputParams *TP, StrBuf *FoundCharset)
1169 wc_mime_attachment *Mime = (wc_mime_attachment *) CTX(CTX_MIME_ATACH);
1172 if (StrLength(Mime->Data) == 0)
1175 Buf = NewStrBufPlain(NULL, StrLength(Mime->Data));
1177 /* HTML is fun, but we've got to strip it first */
1178 output_html(ChrPtr(Mime->Charset),
1179 (WC->CurRoom.view == VIEW_WIKI ? 1 : 0),
1182 FreeStrBuf(&Mime->Data);
1186 #ifdef HAVE_MARKDOWN
1188 char * MarkdownHandleURL(const char* SourceURL, const int len, void* something)
1193 void render_MAIL_markdown(StrBuf *Target, WCTemplputParams *TP, StrBuf *FoundCharset)
1196 wc_mime_attachment *Mime = (wc_mime_attachment *) CTX(CTX_MIME_ATACH);
1198 char *md_as_html = NULL;
1201 if (StrLength(Mime->Data) == 0)
1204 format = bstr("format");
1206 if ((format == NULL) ||
1207 strcmp(format, "plain"))
1209 doc = mkd_string(ChrPtr(Mime->Data), StrLength(Mime->Data), 0);
1210 mkd_basename(doc, "/wiki?page=");
1211 mkd_compile(doc, 0);
1212 if (mkd_document(doc, &md_as_html) != EOF) {
1213 FreeStrBuf(&Mime->Data);
1214 Mime->Data = NewStrBufPlain(md_as_html, -1);
1221 void render_MAIL_UNKNOWN(StrBuf *Target, WCTemplputParams *TP, StrBuf *FoundCharset)
1223 wc_mime_attachment *Mime = (wc_mime_attachment *) CTX(CTX_MIME_ATACH);
1224 /* Unknown weirdness */
1225 FlushStrBuf(Mime->Data);
1226 StrBufAppendBufPlain(Mime->Data, _("I don't know how to display "), -1, 0);
1227 StrBufAppendBuf(Mime->Data, Mime->ContentType, 0);
1228 StrBufAppendBufPlain(Mime->Data, HKEY("<br>\n"), 0);
1232 HashList *iterate_get_mime_All(StrBuf *Target, WCTemplputParams *TP)
1234 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
1235 return Msg->Attachments;
1237 HashList *iterate_get_mime_Submessages(StrBuf *Target, WCTemplputParams *TP)
1239 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
1240 return Msg->Submessages;
1242 HashList *iterate_get_mime_AttachLinks(StrBuf *Target, WCTemplputParams *TP)
1244 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
1245 return Msg->AttachLinks;
1247 HashList *iterate_get_mime_Attachments(StrBuf *Target, WCTemplputParams *TP)
1249 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
1250 return Msg->AllAttach;
1253 void tmplput_MIME_Name(StrBuf *Target, WCTemplputParams *TP)
1255 wc_mime_attachment *mime = (wc_mime_attachment*) CTX(CTX_MIME_ATACH);
1256 StrBufAppendTemplate(Target, TP, mime->Name, 0);
1259 void tmplput_MIME_FileName(StrBuf *Target, WCTemplputParams *TP)
1261 wc_mime_attachment *mime = (wc_mime_attachment*) CTX(CTX_MIME_ATACH);
1262 StrBufAppendTemplate(Target, TP, mime->FileName, 0);
1265 void tmplput_MIME_PartNum(StrBuf *Target, WCTemplputParams *TP)
1267 wc_mime_attachment *mime = (wc_mime_attachment*) CTX(CTX_MIME_ATACH);
1268 StrBufAppendTemplate(Target, TP, mime->PartNum, 0);
1271 void tmplput_MIME_MsgNum(StrBuf *Target, WCTemplputParams *TP)
1273 wc_mime_attachment *mime = (wc_mime_attachment*) CTX(CTX_MIME_ATACH);
1274 StrBufAppendPrintf(Target, "%ld", mime->msgnum);
1277 void tmplput_MIME_Disposition(StrBuf *Target, WCTemplputParams *TP)
1279 wc_mime_attachment *mime = (wc_mime_attachment*) CTX(CTX_MIME_ATACH);
1280 StrBufAppendTemplate(Target, TP, mime->Disposition, 0);
1283 void tmplput_MIME_ContentType(StrBuf *Target, WCTemplputParams *TP)
1285 wc_mime_attachment *mime = (wc_mime_attachment*) CTX(CTX_MIME_ATACH);
1286 StrBufAppendTemplate(Target, TP, mime->ContentType, 0);
1289 void examine_charset(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
1291 Msg->MsgBody->Charset = NewStrBufDup(HdrLine);
1294 void tmplput_MIME_Charset(StrBuf *Target, WCTemplputParams *TP)
1296 wc_mime_attachment *mime = (wc_mime_attachment*) CTX(CTX_MIME_ATACH);
1297 StrBufAppendTemplate(Target, TP, mime->Charset, 0);
1300 void tmplput_MIME_Data(StrBuf *Target, WCTemplputParams *TP)
1302 wc_mime_attachment *mime = (wc_mime_attachment*) CTX(CTX_MIME_ATACH);
1303 if (mime->Renderer != NULL)
1304 mime->Renderer->f(Target, TP, NULL);
1305 StrBufAppendTemplate(Target, TP, mime->Data, 0);
1306 /* TODO: check whether we need to load it now? */
1309 void tmplput_MIME_LoadData(StrBuf *Target, WCTemplputParams *TP)
1311 wcsession *WCC = WC;
1312 wc_mime_attachment *mime = (wc_mime_attachment*) CTX(CTX_MIME_ATACH);
1313 wc_mime_attachment *att;
1315 if (( (!strcasecmp(ChrPtr(mime->Disposition), "inline"))||
1316 (!strcasecmp(ChrPtr(mime->Disposition), "attachment"))) &&
1317 (strcasecmp(ChrPtr(mime->ContentType), "application/ms-tnef")!=0))
1322 /* steal this mime part... */
1323 att = malloc(sizeof(wc_mime_attachment));
1324 memcpy(att, mime, sizeof(wc_mime_attachment));
1325 memset(mime, 0, sizeof(wc_mime_attachment));
1327 if (att->Data == NULL)
1330 if (WCC->attachments == NULL)
1331 WCC->attachments = NewHash(1, NULL);
1332 /* And add it to the list. */
1333 n = snprintf(N, sizeof N, "%d", GetCount(WCC->attachments) + 1);
1334 Put(WCC->attachments, N, n, att, DestroyMime);
1338 void tmplput_MIME_Length(StrBuf *Target, WCTemplputParams *TP)
1340 wc_mime_attachment *mime = (wc_mime_attachment*) CTX(CTX_MIME_ATACH);
1341 StrBufAppendPrintf(Target, "%ld", mime->length);
1344 HashList *iterate_get_registered_Attachments(StrBuf *Target, WCTemplputParams *TP)
1346 return WC->attachments;
1349 void get_registered_Attachments_Count(StrBuf *Target, WCTemplputParams *TP)
1351 StrBufAppendPrintf(Target, "%ld", GetCount (WC->attachments));
1354 void servcmd_do_search(char *buf, long bufsize)
1356 snprintf(buf, bufsize, "MSGS SEARCH|%s", bstr("query"));
1359 void servcmd_headers(char *buf, long bufsize)
1361 snprintf(buf, bufsize, "MSGS ALL");
1364 void servcmd_readfwd(char *buf, long bufsize)
1366 snprintf(buf, bufsize, "MSGS ALL");
1369 void servcmd_readgt(char *buf, long bufsize)
1371 snprintf(buf, bufsize, "MSGS GT|%s", bstr("gt"));
1374 void servcmd_readlt(char *buf, long bufsize)
1376 snprintf(buf, bufsize, "MSGS LT|%s", bstr("lt"));
1379 void servcmd_readnew(char *buf, long bufsize)
1381 snprintf(buf, bufsize, "MSGS NEW");
1384 void servcmd_readold(char *buf, long bufsize)
1386 snprintf(buf, bufsize, "MSGS OLD");
1390 /* DO NOT REORDER OR REMOVE ANY OF THESE */
1391 readloop_struct rlid[] = {
1392 { {HKEY("do_search")}, servcmd_do_search },
1393 { {HKEY("headers")}, servcmd_headers },
1394 { {HKEY("readfwd")}, servcmd_readfwd },
1395 { {HKEY("readnew")}, servcmd_readnew },
1396 { {HKEY("readold")}, servcmd_readold },
1397 { {HKEY("readgt")}, servcmd_readgt },
1398 { {HKEY("readlt")}, servcmd_readlt }
1401 const char* fieldMnemonics[] = {
1402 "from", /* A -> eAuthor */
1403 "exti", /* E -> eXclusivID */
1404 "rfca", /* F -> erFc822Addr */
1405 "hnod", /* H -> eHumanNode */
1406 "msgn", /* I -> emessageId */
1407 "jrnl", /* J -> eJournal */
1408 "rep2", /* K -> eReplyTo */
1409 "list", /* L -> eListID */
1410 "text", /* M -> eMesageText */
1411 "node", /* N -> eNodeName */
1412 "room", /* O -> eOriginalRoom */
1413 "path", /* P -> eMessagePath */
1414 "rcpt", /* R -> eRecipient */
1415 "spec", /* S -> eSpecialField */
1416 "time", /* T -> eTimestamp */
1417 "subj", /* U -> eMsgSubject */
1418 "nvto", /* V -> eenVelopeTo */
1419 "wefw", /* W -> eWeferences */
1420 "cccc" /* Y -> eCarbonCopY */
1422 HashList *msgKeyLookup = NULL;
1424 int GetFieldFromMnemonic(eMessageField *f, const char* c)
1427 if (GetHash(msgKeyLookup, c, 4, &v)) {
1428 *f = (eMessageField) v;
1434 void FillMsgKeyLookupTable(void)
1438 msgKeyLookup = NewHash (1, FourHash);
1440 for (i=0; i < 20; i++) {
1441 if (fieldMnemonics[i] != NULL) {
1442 Put(msgKeyLookup, fieldMnemonics[i], 4, (void*)i, reference_free_handler);
1450 InitModule_MSGRENDERERS
1453 RegisterCTX(CTX_MAILSUM);
1454 RegisterCTX(CTX_MIME_ATACH);
1456 RegisterSortFunc(HKEY("date"),
1462 RegisterSortFunc(HKEY("subject"),
1468 RegisterSortFunc(HKEY("sender"),
1475 RegisterNamespace("SUMM:COUNT", 0, 0, tmplput_SUMM_COUNT, NULL, CTX_NONE);
1476 /* iterate over all known mails in WC->summ */
1477 RegisterIterator("MAIL:SUMM:MSGS", 0, NULL, iterate_get_mailsumm_All,
1478 NULL,NULL, CTX_MAILSUM, CTX_NONE, IT_NOFLAG);
1480 RegisterNamespace("MAIL:SUMM:EUID", 0, 1, tmplput_MAIL_SUMM_EUID, NULL, CTX_MAILSUM);
1481 RegisterNamespace("MAIL:SUMM:DATEBRIEF", 0, 0, tmplput_MAIL_SUMM_DATE_BRIEF, NULL, CTX_MAILSUM);
1482 RegisterNamespace("MAIL:SUMM:DATEFULL", 0, 0, tmplput_MAIL_SUMM_DATE_FULL, NULL, CTX_MAILSUM);
1483 RegisterNamespace("MAIL:SUMM:DATENO", 0, 0, tmplput_MAIL_SUMM_DATE_NO, NULL, CTX_MAILSUM);
1484 RegisterNamespace("MAIL:SUMM:N", 0, 0, tmplput_MAIL_SUMM_N, NULL, CTX_MAILSUM);
1485 RegisterNamespace("MAIL:SUMM:PERMALINK", 0, 0, tmplput_MAIL_SUMM_PERMALINK, NULL, CTX_MAILSUM);
1486 RegisterNamespace("MAIL:SUMM:FROM", 0, 2, tmplput_MAIL_SUMM_FROM, NULL, CTX_MAILSUM);
1487 RegisterNamespace("MAIL:SUMM:TO", 0, 2, tmplput_MAIL_SUMM_TO, NULL, CTX_MAILSUM);
1488 RegisterNamespace("MAIL:SUMM:SUBJECT", 0, 4, tmplput_MAIL_SUMM_SUBJECT, NULL, CTX_MAILSUM);
1489 RegisterNamespace("MAIL:SUMM:NTATACH", 0, 0, tmplput_MAIL_SUMM_NATTACH, NULL, CTX_MAILSUM);
1490 RegisterNamespace("MAIL:SUMM:CCCC", 0, 2, tmplput_MAIL_SUMM_CCCC, NULL, CTX_MAILSUM);
1491 RegisterNamespace("MAIL:SUMM:REPLYTO", 0, 2, tmplput_MAIL_SUMM_REPLYTO, NULL, CTX_MAILSUM);
1492 RegisterNamespace("MAIL:SUMM:H_NODE", 0, 2, tmplput_MAIL_SUMM_H_NODE, NULL, CTX_MAILSUM);
1493 RegisterNamespace("MAIL:SUMM:ALLRCPT", 0, 2, tmplput_MAIL_SUMM_ALLRCPT, NULL, CTX_MAILSUM);
1494 RegisterNamespace("MAIL:SUMM:ORGROOM", 0, 2, tmplput_MAIL_SUMM_ORGROOM, NULL, CTX_MAILSUM);
1495 RegisterNamespace("MAIL:SUMM:RFCA", 0, 2, tmplput_MAIL_SUMM_RFCA, NULL, CTX_MAILSUM);
1496 RegisterNamespace("MAIL:SUMM:OTHERNODE", 2, 0, tmplput_MAIL_SUMM_OTHERNODE, NULL, CTX_MAILSUM);
1497 RegisterNamespace("MAIL:SUMM:REFIDS", 0, 1, tmplput_MAIL_SUMM_REFIDS, NULL, CTX_MAILSUM);
1498 RegisterNamespace("MAIL:SUMM:INREPLYTO", 0, 2, tmplput_MAIL_SUMM_INREPLYTO, NULL, CTX_MAILSUM);
1499 RegisterNamespace("MAIL:BODY", 0, 2, tmplput_MAIL_BODY, NULL, CTX_MAILSUM);
1500 RegisterNamespace("MAIL:QUOTETEXT", 1, 2, tmplput_QUOTED_MAIL_BODY, NULL, CTX_NONE);
1501 RegisterNamespace("MAIL:EDITTEXT", 1, 2, tmplput_EDIT_MAIL_BODY, NULL, CTX_NONE);
1502 RegisterNamespace("MAIL:EDITWIKI", 1, 2, tmplput_EDIT_WIKI_BODY, NULL, CTX_NONE);
1503 RegisterConditional("COND:MAIL:SUMM:RFCA", 0, Conditional_MAIL_SUMM_RFCA, CTX_MAILSUM);
1504 RegisterConditional("COND:MAIL:SUMM:CCCC", 0, Conditional_MAIL_SUMM_CCCC, CTX_MAILSUM);
1505 RegisterConditional("COND:MAIL:SUMM:REPLYTO", 0, Conditional_MAIL_SUMM_REPLYTO, CTX_MAILSUM);
1506 RegisterConditional("COND:MAIL:SUMM:UNREAD", 0, Conditional_MAIL_SUMM_UNREAD, CTX_MAILSUM);
1507 RegisterConditional("COND:MAIL:SUMM:H_NODE", 0, Conditional_MAIL_SUMM_H_NODE, CTX_MAILSUM);
1508 RegisterConditional("COND:MAIL:SUMM:OTHERNODE", 0, Conditional_MAIL_SUMM_OTHERNODE, CTX_MAILSUM);
1509 RegisterConditional("COND:MAIL:SUMM:SUBJECT", 0, Conditional_MAIL_SUMM_SUBJECT, CTX_MAILSUM);
1510 RegisterConditional("COND:MAIL:ANON", 0, Conditional_ANONYMOUS_MESSAGE, CTX_MAILSUM);
1511 RegisterConditional("COND:MAIL:TO", 0, Conditional_MAIL_SUMM_TO, CTX_MAILSUM);
1512 RegisterConditional("COND:MAIL:SUBJ", 0, Conditional_MAIL_SUMM_SUBJ, CTX_MAILSUM);
1514 /* do we have mimetypes to iterate over? */
1515 RegisterConditional("COND:MAIL:MIME:ATTACH", 0, Conditional_MAIL_MIME_ALL, CTX_MAILSUM);
1516 RegisterConditional("COND:MAIL:MIME:ATTACH:SUBMESSAGES", 0, Conditional_MAIL_MIME_SUBMESSAGES, CTX_MAILSUM);
1517 RegisterConditional("COND:MAIL:MIME:ATTACH:LINKS", 0, Conditional_MAIL_MIME_ATTACHLINKS, CTX_MAILSUM);
1518 RegisterConditional("COND:MAIL:MIME:ATTACH:ATT", 0, Conditional_MAIL_MIME_ATTACH, CTX_MAILSUM);
1519 RegisterIterator("MAIL:MIME:ATTACH", 0, NULL, iterate_get_mime_All,
1520 NULL, NULL, CTX_MIME_ATACH, CTX_MAILSUM, IT_NOFLAG);
1521 RegisterIterator("MAIL:MIME:ATTACH:SUBMESSAGES", 0, NULL, iterate_get_mime_Submessages,
1522 NULL, NULL, CTX_MIME_ATACH, CTX_MAILSUM, IT_NOFLAG);
1523 RegisterIterator("MAIL:MIME:ATTACH:LINKS", 0, NULL, iterate_get_mime_AttachLinks,
1524 NULL, NULL, CTX_MIME_ATACH, CTX_MAILSUM, IT_NOFLAG);
1525 RegisterIterator("MAIL:MIME:ATTACH:ATT", 0, NULL, iterate_get_mime_Attachments,
1526 NULL, NULL, CTX_MIME_ATACH, CTX_MAILSUM, IT_NOFLAG);
1528 /* Parts of a mime attachent */
1529 RegisterNamespace("MAIL:MIME:NAME", 0, 2, tmplput_MIME_Name, NULL, CTX_MIME_ATACH);
1530 RegisterNamespace("MAIL:MIME:FILENAME", 0, 2, tmplput_MIME_FileName, NULL, CTX_MIME_ATACH);
1531 RegisterNamespace("MAIL:MIME:PARTNUM", 0, 2, tmplput_MIME_PartNum, NULL, CTX_MIME_ATACH);
1532 RegisterNamespace("MAIL:MIME:MSGNUM", 0, 2, tmplput_MIME_MsgNum, NULL, CTX_MIME_ATACH);
1533 RegisterNamespace("MAIL:MIME:DISPOSITION", 0, 2, tmplput_MIME_Disposition, NULL, CTX_MIME_ATACH);
1534 RegisterNamespace("MAIL:MIME:CONTENTTYPE", 0, 2, tmplput_MIME_ContentType, NULL, CTX_MIME_ATACH);
1535 RegisterNamespace("MAIL:MIME:CHARSET", 0, 2, tmplput_MIME_Charset, NULL, CTX_MIME_ATACH);
1536 RegisterNamespace("MAIL:MIME:LENGTH", 0, 2, tmplput_MIME_Length, NULL, CTX_MIME_ATACH);
1537 RegisterNamespace("MAIL:MIME:DATA", 0, 2, tmplput_MIME_Data, NULL, CTX_MIME_ATACH);
1538 /* load the actual attachment into WC->attachments; no output!!! */
1539 RegisterNamespace("MAIL:MIME:LOADDATA", 0, 0, tmplput_MIME_LoadData, NULL, CTX_MIME_ATACH);
1541 /* iterate the WC->attachments; use the above tokens for their contents */
1542 RegisterIterator("MSG:ATTACHNAMES", 0, NULL, iterate_get_registered_Attachments,
1543 NULL, NULL, CTX_MIME_ATACH, CTX_NONE, IT_NOFLAG);
1545 RegisterNamespace("MSG:NATTACH", 0, 0, get_registered_Attachments_Count, NULL, CTX_NONE);
1547 /* mime renderers translate an attachment into webcit viewable html text */
1548 RegisterMimeRenderer(HKEY("message/rfc822"), render_MAIL, 0, 150);
1550 RegisterMimeRenderer(HKEY("text/calendar"), render_MIME_ICS, 1, 501);
1551 RegisterMimeRenderer(HKEY("application/ics"), render_MIME_ICS, 1, 500);
1553 RegisterMimeRenderer(HKEY("text/x-citadel-variformat"), render_MAIL_variformat, 1, 2);
1554 RegisterMimeRenderer(HKEY("text/plain"), render_MAIL_text_plain, 1, 3);
1555 RegisterMimeRenderer(HKEY("text"), render_MAIL_text_plain, 1, 1);
1556 RegisterMimeRenderer(HKEY("text/html"), render_MAIL_html, 1, 100);
1557 #ifdef HAVE_MARKDOWN
1558 RegisterMimeRenderer(HKEY("text/x-markdown"), render_MAIL_markdown, 1, 30);
1560 RegisterMimeRenderer(HKEY(""), render_MAIL_UNKNOWN, 0, 0);
1562 FillMsgKeyLookupTable();
1564 /* these headers are citserver replies to MSG4 and friends. one evaluator for each */
1565 RegisterMsgHdr(HKEY("nhdr"), examine_nhdr, 0);
1566 RegisterMsgHdr(HKEY("type"), examine_type, 0);
1567 RegisterMsgHdr(HKEY("from"), examine_from, 0);
1568 RegisterMsgHdr(HKEY("subj"), examine_subj, 0);
1569 RegisterMsgHdr(HKEY("msgn"), examine_msgn, 0);
1570 RegisterMsgHdr(HKEY("wefw"), examine_wefw, 0);
1571 RegisterMsgHdr(HKEY("cccc"), examine_cccc, 0);
1572 RegisterMsgHdr(HKEY("rep2"), examine_replyto, 0);
1573 RegisterMsgHdr(HKEY("hnod"), examine_hnod, 0);
1574 RegisterMsgHdr(HKEY("room"), examine_room, 0);
1575 RegisterMsgHdr(HKEY("rfca"), examine_rfca, 0);
1576 RegisterMsgHdr(HKEY("node"), examine_node, 0);
1577 RegisterMsgHdr(HKEY("rcpt"), examine_rcpt, 0);
1578 RegisterMsgHdr(HKEY("nvto"), examine_nvto, 0);
1579 RegisterMsgHdr(HKEY("time"), examine_time, 0);
1580 RegisterMsgHdr(HKEY("part"), examine_mime_part, 0);
1581 RegisterMsgHdr(HKEY("text"), examine_text, 1);
1582 /* these are the content-type headers we get infront of a message; put it into the same hash since it doesn't clash. */
1583 RegisterMsgHdr(HKEY("X-Citadel-MSG4-Partnum"), examine_msg4_partnum, 0);
1584 RegisterMsgHdr(HKEY("Content-type"), examine_content_type, 0);
1585 RegisterMsgHdr(HKEY("Content-length"), examine_content_lengh, 0);
1586 RegisterMsgHdr(HKEY("Content-transfer-encoding"), examine_content_encoding, 0); /* do we care? */
1587 RegisterMsgHdr(HKEY("charset"), examine_charset, 0);
1589 /* Don't care about these... */
1590 RegisterMsgHdr(HKEY("pref"), examine_pref, 0);
1591 RegisterMsgHdr(HKEY("suff"), examine_suff, 0);
1592 RegisterMsgHdr(HKEY("path"), examine_path, 0);
1596 InitModule2_MSGRENDERERS
1599 /* and finalize the anouncement to the server... */
1603 ServerStartModule_MSGRENDERERS
1606 DflMsgHeaderHandler = NewHash (1, FourHash);
1607 MsgHeaderHandler = NewHash(1, NULL);
1608 MimeRenderHandler = NewHash(1, NULL);
1609 ReadLoopHandler = NewHash(1, NULL);
1613 ServerShutdownModule_MSGRENDERERS
1616 DeleteHash(&MsgHeaderHandler);
1617 DeleteHash(&MimeRenderHandler);
1618 DeleteHash(&ReadLoopHandler);
1619 DeleteHash(&msgKeyLookup);
1623 SessionDestroyModule_MSGRENDERERS
1626 DeleteHash(&sess->attachments);
1627 FreeStrBuf(&sess->ConvertBuf1);
1628 FreeStrBuf(&sess->ConvertBuf2);