1 /*----------------------------------------------------------------------------*/
6 * message index functions
10 void DestroyMimeParts(wc_mime_attachment *Mime)
12 FreeStrBuf(&Mime->Name);
13 FreeStrBuf(&Mime->FileName);
14 FreeStrBuf(&Mime->PartNum);
15 FreeStrBuf(&Mime->Disposition);
16 FreeStrBuf(&Mime->ContentType);
17 FreeStrBuf(&Mime->Charset);
18 FreeStrBuf(&Mime->Data);
21 void DestroyMime(void *vMime)
23 wc_mime_attachment *Mime = (wc_mime_attachment*)vMime;
24 DestroyMimeParts(Mime);
28 void DestroyMessageSummary(void *vMsg)
30 message_summary *Msg = (message_summary*) vMsg;
32 FreeStrBuf(&Msg->from);
34 FreeStrBuf(&Msg->subj);
35 FreeStrBuf(&Msg->reply_inreplyto);
36 FreeStrBuf(&Msg->reply_references);
37 FreeStrBuf(&Msg->cccc);
38 FreeStrBuf(&Msg->hnod);
39 FreeStrBuf(&Msg->AllRcpt);
40 FreeStrBuf(&Msg->Room);
41 FreeStrBuf(&Msg->Rfca);
42 FreeStrBuf(&Msg->OtherNode);
44 FreeStrBuf(&Msg->reply_to);
46 DeleteHash(&Msg->Attachments); /**< list of Accachments */
47 DeleteHash(&Msg->Submessages);
48 DeleteHash(&Msg->AttachLinks);
49 DeleteHash(&Msg->AllAttach);
55 void RegisterMsgHdr(const char *HeaderName, long HdrNLen, ExamineMsgHeaderFunc evaluator, int type)
58 ev = (headereval*) malloc(sizeof(headereval));
59 ev->evaluator = evaluator;
61 Put(MsgHeaderHandler, HeaderName, HdrNLen, ev, NULL);
64 void RegisterMimeRenderer(const char *HeaderName, long HdrNLen, RenderMimeFunc MimeRenderer)
66 RenderMimeFuncStruct *f;
68 f = (RenderMimeFuncStruct*) malloc(sizeof(RenderMimeFuncStruct));
70 Put(MimeRenderHandler, HeaderName, HdrNLen, f, NULL);
74 /*----------------------------------------------------------------------------*/
77 * comparator for two longs in descending order.
79 int longcmp_r(const void *s1, const void *s2) {
83 l1 = *(long *)GetSearchPayload(s1);
84 l2 = *(long *)GetSearchPayload(s2);
86 if (l1 > l2) return(-1);
87 if (l1 < l2) return(+1);
92 * comparator for longs; descending order.
94 int qlongcmp_r(const void *s1, const void *s2) {
98 if (l1 > l2) return(-1);
99 if (l1 < l2) return(+1);
105 * comparator for message summary structs by ascending subject.
107 int summcmp_subj(const void *s1, const void *s2) {
108 message_summary *summ1;
109 message_summary *summ2;
111 summ1 = (message_summary *)GetSearchPayload(s1);
112 summ2 = (message_summary *)GetSearchPayload(s2);
113 return strcasecmp(ChrPtr(summ1->subj), ChrPtr(summ2->subj));
117 * comparator for message summary structs by descending subject.
119 int summcmp_rsubj(const void *s1, const void *s2) {
120 message_summary *summ1;
121 message_summary *summ2;
123 summ1 = (message_summary *)GetSearchPayload(s1);
124 summ2 = (message_summary *)GetSearchPayload(s2);
125 return strcasecmp(ChrPtr(summ2->subj), ChrPtr(summ1->subj));
128 * comparator for message summary structs by descending subject.
130 int groupchange_subj(const void *s1, const void *s2) {
131 message_summary *summ1;
132 message_summary *summ2;
134 summ1 = (message_summary *)s1;
135 summ2 = (message_summary *)s2;
136 return ChrPtr(summ2->subj)[0] != ChrPtr(summ1->subj)[0];
140 * comparator for message summary structs by ascending sender.
142 int summcmp_sender(const void *s1, const void *s2) {
143 message_summary *summ1;
144 message_summary *summ2;
146 summ1 = (message_summary *)GetSearchPayload(s1);
147 summ2 = (message_summary *)GetSearchPayload(s2);
148 return strcasecmp(ChrPtr(summ1->from), ChrPtr(summ2->from));
152 * comparator for message summary structs by descending sender.
154 int summcmp_rsender(const void *s1, const void *s2) {
155 message_summary *summ1;
156 message_summary *summ2;
158 summ1 = (message_summary *)GetSearchPayload(s1);
159 summ2 = (message_summary *)GetSearchPayload(s2);
160 return strcasecmp(ChrPtr(summ2->from), ChrPtr(summ1->from));
163 * comparator for message summary structs by descending sender.
165 int groupchange_sender(const void *s1, const void *s2) {
166 message_summary *summ1;
167 message_summary *summ2;
169 summ1 = (message_summary *)s1;
170 summ2 = (message_summary *)s2;
171 return strcasecmp(ChrPtr(summ2->from), ChrPtr(summ1->from)) != 0;
176 * comparator for message summary structs by ascending date.
178 int summcmp_date(const void *s1, const void *s2) {
179 message_summary *summ1;
180 message_summary *summ2;
182 summ1 = (message_summary *)GetSearchPayload(s1);
183 summ2 = (message_summary *)GetSearchPayload(s2);
185 if (summ1->date < summ2->date) return -1;
186 else if (summ1->date > summ2->date) return +1;
191 * comparator for message summary structs by descending date.
193 int summcmp_rdate(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 const long DAYSECONDS = 24 * 60 * 60;
209 int groupchange_date(const void *s1, const void *s2) {
210 message_summary *summ1;
211 message_summary *summ2;
213 summ1 = (message_summary *)s1;
214 summ2 = (message_summary *)s2;
216 return (summ1->date % DAYSECONDS) != (summ2->date %DAYSECONDS);
220 /*----------------------------------------------------------------------------*/
221 /* Don't wanna know... or? */
222 void examine_pref(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset) {return;}
223 void examine_suff(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset) {return;}
224 void examine_path(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset) {return;}
225 void examine_content_encoding(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
227 /* TODO: do we care? */
230 void examine_nhdr(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
233 if (!strncasecmp(ChrPtr(HdrLine), "yes", 8))
236 int Conditional_ANONYMOUS_MESSAGE(StrBuf *Target, WCTemplputParams *TP)
238 message_summary *Msg = (message_summary*) CTX;
239 return Msg->nhdr != 0;
242 void examine_type(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
244 Msg->format_type = StrToi(HdrLine);
248 void examine_from(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
250 FreeStrBuf(&Msg->from);
251 Msg->from = NewStrBufPlain(NULL, StrLength(HdrLine));
252 StrBuf_RFC822_to_Utf8(Msg->from, HdrLine, WC->DefaultCharset, FoundCharset);
254 void tmplput_MAIL_SUMM_FROM(StrBuf *Target, WCTemplputParams *TP)
256 message_summary *Msg = (message_summary*) CTX;
257 StrBufAppendTemplate(Target, TP, Msg->from, 0);
262 void examine_subj(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
264 FreeStrBuf(&Msg->subj);
265 Msg->subj = NewStrBufPlain(NULL, StrLength(HdrLine));
266 StrBuf_RFC822_to_Utf8(Msg->subj, HdrLine, WC->DefaultCharset, FoundCharset);
268 void tmplput_MAIL_SUMM_SUBJECT(StrBuf *Target, WCTemplputParams *TP)
269 {/*////TODO: Fwd: and RE: filter!!*/
271 message_summary *Msg = (message_summary*) CTX;
272 StrBufAppendTemplate(Target, TP, Msg->subj, 0);
276 void examine_msgn(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
278 FreeStrBuf(&Msg->reply_inreplyto);
279 Msg->reply_inreplyto = NewStrBufPlain(NULL, StrLength(HdrLine));
280 StrBuf_RFC822_to_Utf8(Msg->reply_inreplyto, HdrLine, WC->DefaultCharset, FoundCharset);
282 void tmplput_MAIL_SUMM_INREPLYTO(StrBuf *Target, WCTemplputParams *TP)
284 message_summary *Msg = (message_summary*) CTX;
285 StrBufAppendTemplate(Target, TP, Msg->reply_inreplyto, 0);
288 int Conditional_MAIL_SUMM_UNREAD(StrBuf *Target, WCTemplputParams *TP)
290 message_summary *Msg = (message_summary*) CTX;
291 return Msg->is_new != 0;
294 void examine_wefw(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
296 FreeStrBuf(&Msg->reply_references);
297 Msg->reply_references = NewStrBufPlain(NULL, StrLength(HdrLine));
298 StrBuf_RFC822_to_Utf8(Msg->reply_references, HdrLine, WC->DefaultCharset, FoundCharset);
300 void tmplput_MAIL_SUMM_REFIDS(StrBuf *Target, WCTemplputParams *TP)
302 message_summary *Msg = (message_summary*) CTX;
303 StrBufAppendTemplate(Target, TP, Msg->reply_references, 0);
307 void examine_cccc(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
309 FreeStrBuf(&Msg->cccc);
310 Msg->cccc = NewStrBufPlain(NULL, StrLength(HdrLine));
311 StrBuf_RFC822_to_Utf8(Msg->cccc, HdrLine, WC->DefaultCharset, FoundCharset);
312 if (Msg->AllRcpt == NULL)
313 Msg->AllRcpt = NewStrBufPlain(NULL, StrLength(HdrLine));
314 if (StrLength(Msg->AllRcpt) > 0) {
315 StrBufAppendBufPlain(Msg->AllRcpt, HKEY(", "), 0);
317 StrBufAppendBuf(Msg->AllRcpt, Msg->cccc, 0);
319 void tmplput_MAIL_SUMM_CCCC(StrBuf *Target, WCTemplputParams *TP)
321 message_summary *Msg = (message_summary*) CTX;
322 StrBufAppendTemplate(Target, TP, Msg->cccc, 0);
326 void examine_room(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
328 if ((StrLength(HdrLine) > 0) &&
329 (strcasecmp(ChrPtr(HdrLine), ChrPtr(WC->wc_roomname)))) {
330 FreeStrBuf(&Msg->Room);
331 Msg->Room = NewStrBufDup(HdrLine);
334 void tmplput_MAIL_SUMM_ORGROOM(StrBuf *Target, WCTemplputParams *TP)
336 message_summary *Msg = (message_summary*) CTX;
337 StrBufAppendTemplate(Target, TP, Msg->Room, 0);
341 void examine_rfca(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
343 FreeStrBuf(&Msg->Rfca);
344 Msg->Rfca = NewStrBufDup(HdrLine);
346 void tmplput_MAIL_SUMM_RFCA(StrBuf *Target, WCTemplputParams *TP)
348 message_summary *Msg = (message_summary*) CTX;
349 StrBufAppendTemplate(Target, TP, Msg->Rfca, 0);
351 int Conditional_MAIL_SUMM_RFCA(StrBuf *Target, WCTemplputParams *TP)
353 message_summary *Msg = (message_summary*) CTX;
354 return StrLength(Msg->Rfca) > 0;
356 int Conditional_MAIL_SUMM_CCCC(StrBuf *Target, WCTemplputParams *TP)
358 message_summary *Msg = (message_summary*) CTX;
359 return StrLength(Msg->cccc) > 0;
362 void examine_node(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
364 if ( (StrLength(HdrLine) > 0) &&
365 ((WC->room_flags & QR_NETWORK)
366 || ((strcasecmp(ChrPtr(HdrLine), ChrPtr(serv_info.serv_nodename))
367 && (strcasecmp(ChrPtr(HdrLine), ChrPtr(serv_info.serv_fqdn))))))) {
368 FreeStrBuf(&Msg->OtherNode);
369 Msg->OtherNode = NewStrBufDup(HdrLine);
372 void tmplput_MAIL_SUMM_OTHERNODE(StrBuf *Target, WCTemplputParams *TP)
374 message_summary *Msg = (message_summary*) CTX;
375 StrBufAppendTemplate(Target, TP, Msg->OtherNode, 0);
377 int Conditional_MAIL_SUMM_OTHERNODE(StrBuf *Target, WCTemplputParams *TP)
379 message_summary *Msg = (message_summary*) CTX;
380 return StrLength(Msg->OtherNode) > 0;
384 void examine_rcpt(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
386 FreeStrBuf(&Msg->to);
387 Msg->to = NewStrBufPlain(NULL, StrLength(HdrLine));
388 StrBuf_RFC822_to_Utf8(Msg->to, HdrLine, WC->DefaultCharset, FoundCharset);
389 if (Msg->AllRcpt == NULL)
390 Msg->AllRcpt = NewStrBufPlain(NULL, StrLength(HdrLine));
391 if (StrLength(Msg->AllRcpt) > 0) {
392 StrBufAppendBufPlain(Msg->AllRcpt, HKEY(", "), 0);
394 StrBufAppendBuf(Msg->AllRcpt, Msg->to, 0);
396 void tmplput_MAIL_SUMM_TO(StrBuf *Target, WCTemplputParams *TP)
398 message_summary *Msg = (message_summary*) CTX;
399 StrBufAppendTemplate(Target, TP, Msg->to, 0);
401 void tmplput_MAIL_SUMM_ALLRCPT(StrBuf *Target, WCTemplputParams *TP)
403 message_summary *Msg = (message_summary*) CTX;
404 StrBufAppendTemplate(Target, TP, Msg->AllRcpt, 0);
408 HashList *iterate_get_mailsumm_All(StrBuf *Target, WCTemplputParams *TP)
412 int Conditional_ROOM_DISPLAY_MSG(StrBuf *Target, WCTemplputParams *TP) {
414 IterateStruct *ITC = CCTX;
415 int num_inset = ITC->n;
416 if ((num_inset >= WC->startmsg) && (WCC->num_displayed <= WCC->maxmsgs)) {
417 WCC->num_displayed = WCC->num_displayed+1;
418 return 1; /* Pass GO, collect $200 */
422 int Conditional_MAIL_SUMM_LASTMSG(StrBuf *Target, WCTemplputParams *TP) {
423 IterateStruct *ITC = CCTX;
424 int is_last_n = ITC->LastN;
426 //GetHash(WC->vars, HKEY("ITERATE:N"), (void *)&n_dsubst);
427 //num_inset = n_dsubst->lvalue;
429 /* Is the num_displayed higher than maxmsgs? OR last in iterator */
430 return ((WC->num_displayed > WC->maxmsgs) || (is_last_n == 1));
432 void examine_time(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
434 Msg->date = StrTol(HdrLine);
437 void tmplput_MAIL_SUMM_DATE_BRIEF(StrBuf *Target, WCTemplputParams *TP)
440 message_summary *Msg = (message_summary*) CTX;
441 webcit_fmt_date(datebuf, Msg->date, 1);
442 StrBufAppendBufPlain(Target, datebuf, -1, 0);
445 void tmplput_MAIL_SUMM_DATE_FULL(StrBuf *Target, WCTemplputParams *TP)
448 message_summary *Msg = (message_summary*) CTX;
449 webcit_fmt_date(datebuf, Msg->date, 0);
450 StrBufAppendBufPlain(Target, datebuf, -1, 0);
452 void tmplput_MAIL_SUMM_DATE_NO(StrBuf *Target, WCTemplputParams *TP)
454 message_summary *Msg = (message_summary*) CTX;
455 StrBufAppendPrintf(Target, "%ld", Msg->date, 0);
460 void render_MAIL(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCharset)
462 Mime->Data = NewStrBufPlain(NULL, Mime->length);
463 read_message(Mime->Data, HKEY("view_submessage"), Mime->msgnum, 0, Mime->PartNum);
465 if ( (!IsEmptyStr(mime_submessages)) && (!section[0]) ) {
466 for (i=0; i<num_tokens(mime_submessages, '|'); ++i) {
467 extract_token(buf, mime_submessages, i, '|', sizeof buf);
468 / ** use printable_view to suppress buttons * /
469 wprintf("<blockquote>");
470 read_message(Mime->msgnum, 1, ChrPtr(Mime->Section));
471 wprintf("</blockquote>");
477 void render_MIME_VCard(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCharset)
481 if (StrLength(Mime->Data) > 0) {
484 /** If it's my vCard I can edit it */
485 if ( (!strcasecmp(ChrPtr(WCC->wc_roomname), USERCONFIGROOM))
486 || (!strcasecmp(&(ChrPtr(WCC->wc_roomname)[11]), USERCONFIGROOM))
487 || (WC->wc_view == VIEW_ADDRESSBOOK)
489 StrBufAppendPrintf(Buf, "<a href=\"edit_vcard?msgnum=%ld&partnum=%s\">",
490 Mime->msgnum, ChrPtr(Mime->PartNum));
491 StrBufAppendPrintf(Buf, "[%s]</a>", _("edit"));
494 /* In all cases, display the full card */
495 display_vcard(Buf, ChrPtr(Mime->Data), 0, 1, NULL, Mime->msgnum);
496 FreeStrBuf(&Mime->Data);
502 void render_MIME_ICS(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCharset)
504 if (StrLength(Mime->Data) == 0) {
507 if (StrLength(Mime->Data) > 0) {
508 cal_process_attachment(Mime);
514 void examine_mime_part(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
516 wc_mime_attachment *Mime;
519 Mime = (wc_mime_attachment*) malloc(sizeof(wc_mime_attachment));
520 memset(Mime, 0, sizeof(wc_mime_attachment));
521 Mime->msgnum = Msg->msgnum;
524 Mime->Name = NewStrBuf();
525 StrBufExtract_token(Buf, HdrLine, 0, '|');
526 StrBuf_RFC822_to_Utf8(Mime->Name, Buf, WC->DefaultCharset, FoundCharset);
527 StrBufTrim(Mime->Name);
529 StrBufExtract_token(Buf, HdrLine, 1, '|');
530 Mime->FileName = NewStrBuf();
531 StrBuf_RFC822_to_Utf8(Mime->FileName, Buf, WC->DefaultCharset, FoundCharset);
532 StrBufTrim(Mime->FileName);
534 Mime->PartNum = NewStrBuf();
535 StrBufExtract_token(Mime->PartNum, HdrLine, 2, '|');
536 StrBufTrim(Mime->PartNum);
537 if (strchr(ChrPtr(Mime->PartNum), '.') != NULL)
542 Mime->Disposition = NewStrBuf();
543 StrBufExtract_token(Mime->Disposition, HdrLine, 3, '|');
545 Mime->ContentType = NewStrBuf();
546 StrBufExtract_token(Mime->ContentType, HdrLine, 4, '|');
547 StrBufTrim(Mime->ContentType);
548 StrBufLowerCase(Mime->ContentType);
550 Mime->length = StrBufExtract_int(HdrLine, 5, '|');
552 if ( (StrLength(Mime->FileName) == 0) && (StrLength(Mime->Name) > 0) ) {
553 StrBufAppendBuf(Mime->FileName, Mime->Name, 0);
556 if (StrLength(Msg->PartNum) > 0) {
558 StrBufPrintf(Buf, "%s.%s", ChrPtr(Msg->PartNum), ChrPtr(Mime->PartNum));
564 if (Msg->AllAttach == NULL)
565 Msg->AllAttach = NewHash(1,NULL);
566 Put(Msg->AllAttach, SKEY(Mime->PartNum), Mime, DestroyMime);
571 void evaluate_mime_part(message_summary *Msg, wc_mime_attachment *Mime)
575 /* just print the root-node */
576 if ((Mime->level == 1) &&
577 GetHash(MimeRenderHandler, SKEY(Mime->ContentType), &vMimeRenderer) &&
578 vMimeRenderer != NULL)
580 Mime->Renderer = (RenderMimeFuncStruct*) vMimeRenderer;
581 if (Msg->Submessages == NULL)
582 Msg->Submessages = NewHash(1,NULL);
583 Put(Msg->Submessages, SKEY(Mime->PartNum), Mime, reference_free_handler);
585 else if ((Mime->level == 1) &&
586 (!strcasecmp(ChrPtr(Mime->Disposition), "inline"))
587 && (!strncasecmp(ChrPtr(Mime->ContentType), "image/", 6)) ){
588 if (Msg->AttachLinks == NULL)
589 Msg->AttachLinks = NewHash(1,NULL);
590 Put(Msg->AttachLinks, SKEY(Mime->PartNum), Mime, reference_free_handler);
592 else if ((Mime->level == 1) &&
593 (StrLength(Mime->ContentType) > 0) &&
594 ( (!strcasecmp(ChrPtr(Mime->Disposition), "attachment"))
595 || (!strcasecmp(ChrPtr(Mime->Disposition), "inline"))
596 || (!strcasecmp(ChrPtr(Mime->Disposition), ""))))
598 if (Msg->AttachLinks == NULL)
599 Msg->AttachLinks = NewHash(1,NULL);
600 Put(Msg->AttachLinks, SKEY(Mime->PartNum), Mime, reference_free_handler);
601 if ((strcasecmp(ChrPtr(Mime->ContentType), "application/octet-stream") == 0) &&
602 (StrLength(Mime->FileName) > 0)) {
603 FlushStrBuf(Mime->ContentType);
604 StrBufAppendBufPlain(Mime->ContentType,
605 GuessMimeByFilename(SKEY(Mime->FileName)),
611 void tmplput_MAIL_SUMM_NATTACH(StrBuf *Target, WCTemplputParams *TP)
613 message_summary *Msg = (message_summary*) CTX;
614 StrBufAppendPrintf(Target, "%ld", GetCount(Msg->Attachments));
618 void examine_hnod(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
620 FreeStrBuf(&Msg->hnod);
621 Msg->hnod = NewStrBufPlain(NULL, StrLength(HdrLine));
622 StrBuf_RFC822_to_Utf8(Msg->hnod, HdrLine, WC->DefaultCharset, FoundCharset);
624 void tmplput_MAIL_SUMM_H_NODE(StrBuf *Target, WCTemplputParams *TP)
626 message_summary *Msg = (message_summary*) CTX;
627 StrBufAppendTemplate(Target, TP, Msg->hnod, 0);
629 int Conditional_MAIL_SUMM_H_NODE(StrBuf *Target, WCTemplputParams *TP)
631 message_summary *Msg = (message_summary*) CTX;
632 return StrLength(Msg->hnod) > 0;
637 void examine_text(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
639 Msg->MsgBody->Data = NewStrBuf();
642 void examine_msg4_partnum(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
644 Msg->MsgBody->PartNum = NewStrBufDup(HdrLine);
645 StrBufTrim(Msg->MsgBody->PartNum);
648 void examine_content_lengh(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
650 Msg->MsgBody->length = StrTol(HdrLine);
651 Msg->MsgBody->size_known = 1;
654 void examine_content_type(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
664 Msg->MsgBody->ContentType = NewStrBufDup(HdrLine);
665 sem = strchr(ChrPtr(HdrLine), ';');
668 Token = NewStrBufPlain(NULL, StrLength(HdrLine));
669 Value = NewStrBufPlain(NULL, StrLength(HdrLine));
670 len = sem - ChrPtr(HdrLine);
671 StrBufCutAt(Msg->MsgBody->ContentType, len, NULL);
672 while (sem != NULL) {
673 while (isspace(*(sem + 1)))
675 StrBufCutLeft(HdrLine, sem - ChrPtr(HdrLine));
676 sem = strchr(ChrPtr(HdrLine), ';');
678 len = sem - ChrPtr(HdrLine);
680 len = StrLength(HdrLine);
683 StrBufAppendBufPlain(Token, ChrPtr(HdrLine), len, 0);
684 eq = strchr(ChrPtr(Token), '=');
686 len = eq - ChrPtr(Token);
687 StrBufAppendBufPlain(Value, eq + 1, StrLength(Token) - len - 1, 0);
688 StrBufCutAt(Token, len, NULL);
693 if (GetHash(MsgHeaderHandler, SKEY(Token), &vHdr) &&
695 Hdr = (headereval*)vHdr;
696 Hdr->evaluator(Msg, Value, FoundCharset);
698 else lprintf(1, "don't know how to handle content type sub-header[%s]\n", ChrPtr(Token));
705 void tmplput_MAIL_SUMM_N(StrBuf *Target, WCTemplputParams *TP)
707 message_summary *Msg = (message_summary*) CTX;
708 StrBufAppendPrintf(Target, "%ld", Msg->msgnum);
713 int Conditional_MAIL_MIME_ALL(StrBuf *Target, WCTemplputParams *TP)
715 message_summary *Msg = (message_summary*) CTX;
716 return GetCount(Msg->Attachments) > 0;
719 int Conditional_MAIL_MIME_SUBMESSAGES(StrBuf *Target, WCTemplputParams *TP)
721 message_summary *Msg = (message_summary*) CTX;
722 return GetCount(Msg->Submessages) > 0;
725 int Conditional_MAIL_MIME_ATTACHLINKS(StrBuf *Target, WCTemplputParams *TP)
727 message_summary *Msg = (message_summary*) CTX;
728 return GetCount(Msg->AttachLinks) > 0;
731 int Conditional_MAIL_MIME_ATTACH(StrBuf *Target, WCTemplputParams *TP)
733 message_summary *Msg = (message_summary*) CTX;
734 return GetCount(Msg->AllAttach) > 0;
739 /*----------------------------------------------------------------------------*/
740 void tmplput_QUOTED_MAIL_BODY(StrBuf *Target, WCTemplputParams *TP)
745 MsgNum = LBstr(TKEY(0));
747 read_message(Buf, HKEY("view_message_replyquote"), MsgNum, 0, NULL);
748 StrBufAppendTemplate(Target, TP, Buf, 1);
752 void tmplput_MAIL_BODY(StrBuf *Target, WCTemplputParams *TP)
754 message_summary *Msg = (message_summary*) CTX;
755 StrBufAppendTemplate(Target, TP, Msg->MsgBody->Data, 0);
759 void render_MAIL_variformat(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCharset)
761 /* Messages in legacy Citadel variformat get handled thusly... */
762 StrBuf *Target = NewStrBufPlain(NULL, StrLength(Mime->Data));
763 FmOut(Target, "JUSTIFY", Mime->Data);
764 FreeStrBuf(&Mime->Data);
768 void render_MAIL_text_plain(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCharset)
771 const char *ptr, *pte;
772 const char *BufPtr = NULL;
784 iconv_t ic = (iconv_t)(-1) ;
787 if ((StrLength(Mime->Data) == 0) && (Mime->length > 0)) {
788 FreeStrBuf(&Mime->Data);
792 /* Boring old 80-column fixed format text gets handled this way... */
793 if ((strcasecmp(ChrPtr(Mime->Charset), "us-ascii") == 0) &&
794 (strcasecmp(ChrPtr(Mime->Charset), "UTF-8") == 0))
799 if (StrLength(Mime->Charset) != 0)
801 else if (StrLength(FoundCharset) > 0)
803 else if (StrLength(WC->DefaultCharset) > 0)
804 cs = WC->DefaultCharset;
809 ctdl_iconv_open("UTF-8", ChrPtr(cs), &ic);
810 if (ic == (iconv_t)(-1) ) {
811 lprintf(5, "%s:%d iconv_open(UTF-8, %s) failed: %s\n",
812 __FILE__, __LINE__, ChrPtr(Mime->Charset), strerror(errno));
820 Target = NewStrBufPlain(NULL, StrLength(Mime->Data));
822 while ((n = StrBufSipLine(Line, Mime->Data, &BufPtr), n >= 0) && !done)
828 len = StrLength(Line);
831 while ((ptr < pte) &&
840 if (i > 0) StrBufCutLeft(Line, i);
842 if (StrLength(Line) == 0)
845 for (i = bn; i < bq; i++)
846 StrBufAppendBufPlain(Target, HKEY("<blockquote>"), 0);
847 for (i = bq; i < bn; i++)
848 StrBufAppendBufPlain(Target, HKEY("</blockquote>"), 0);
850 if (ConvertIt == 1) {
851 StrBufConvert(Line, Line1, &ic);
854 StrBufAppendBufPlain(Target, HKEY("<tt>"), 0);
855 UrlizeText(Line1, Line, Line2);
857 StrEscAppend(Target, Line1, NULL, 0, 0);
858 StrBufAppendBufPlain(Target, HKEY("</tt><br />\n"), 0);
862 for (i = 0; i < bn; i++)
863 StrBufAppendBufPlain(Target, HKEY("</blockquote>"), 0);
865 StrBufAppendBufPlain(Target, HKEY("</i><br />"), 0);
867 if (ic != (iconv_t)(-1) ) {
872 FreeStrBuf(&Mime->Data);
874 FlushStrBuf(Mime->ContentType);
875 StrBufAppendBufPlain(Mime->ContentType, HKEY("text/html"), 0);
876 FlushStrBuf(Mime->Charset);
877 StrBufAppendBufPlain(Mime->Charset, HKEY("UTF-8"), 0);
883 void render_MAIL_html(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCharset)
887 if (StrLength(Mime->Data) == 0)
890 Buf = NewStrBufPlain(NULL, StrLength(Mime->Data));
892 /* HTML is fun, but we've got to strip it first */
893 output_html(ChrPtr(Mime->Charset),
894 (WC->wc_view == VIEW_WIKI ? 1 : 0),
897 FreeStrBuf(&Mime->Data);
901 void render_MAIL_UNKNOWN(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCharset)
903 /* Unknown weirdness */
904 FlushStrBuf(Mime->Data);
905 StrBufAppendBufPlain(Mime->Data, _("I don't know how to display "), -1, 0);
906 StrBufAppendBuf(Mime->Data, Mime->ContentType, 0);
907 StrBufAppendBufPlain(Mime->Data, HKEY("<br />\n"), 0);
915 HashList *iterate_get_mime_All(StrBuf *Target, WCTemplputParams *TP)
917 message_summary *Msg = (message_summary*) CTX;
918 return Msg->Attachments;
920 HashList *iterate_get_mime_Submessages(StrBuf *Target, WCTemplputParams *TP)
922 message_summary *Msg = (message_summary*) CTX;
923 return Msg->Submessages;
925 HashList *iterate_get_mime_AttachLinks(StrBuf *Target, WCTemplputParams *TP)
927 message_summary *Msg = (message_summary*) CTX;
928 return Msg->AttachLinks;
930 HashList *iterate_get_mime_Attachments(StrBuf *Target, WCTemplputParams *TP)
932 message_summary *Msg = (message_summary*) CTX;
933 return Msg->AllAttach;
936 void tmplput_MIME_Name(StrBuf *Target, WCTemplputParams *TP)
938 wc_mime_attachment *mime = (wc_mime_attachment*) CTX;
939 StrBufAppendTemplate(Target, TP, mime->Name, 0);
942 void tmplput_MIME_FileName(StrBuf *Target, WCTemplputParams *TP)
944 wc_mime_attachment *mime = (wc_mime_attachment*) CTX;
945 StrBufAppendTemplate(Target, TP, mime->FileName, 0);
948 void tmplput_MIME_PartNum(StrBuf *Target, WCTemplputParams *TP)
950 wc_mime_attachment *mime = (wc_mime_attachment*) CTX;
951 StrBufAppendTemplate(Target, TP, mime->PartNum, 0);
954 void tmplput_MIME_MsgNum(StrBuf *Target, WCTemplputParams *TP)
956 wc_mime_attachment *mime = (wc_mime_attachment*) CTX;
957 StrBufAppendPrintf(Target, "%ld", mime->msgnum);
960 void tmplput_MIME_Disposition(StrBuf *Target, WCTemplputParams *TP)
962 wc_mime_attachment *mime = (wc_mime_attachment*) CTX;
963 StrBufAppendTemplate(Target, TP, mime->Disposition, 0);
966 void tmplput_MIME_ContentType(StrBuf *Target, WCTemplputParams *TP)
968 wc_mime_attachment *mime = (wc_mime_attachment*) CTX;
969 StrBufAppendTemplate(Target, TP, mime->ContentType, 0);
972 void examine_charset(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
974 Msg->MsgBody->Charset = NewStrBufDup(HdrLine);
977 void tmplput_MIME_Charset(StrBuf *Target, WCTemplputParams *TP)
979 wc_mime_attachment *mime = (wc_mime_attachment*) CTX;
980 StrBufAppendTemplate(Target, TP, mime->Charset, 0);
983 void tmplput_MIME_Data(StrBuf *Target, WCTemplputParams *TP)
985 wc_mime_attachment *mime = (wc_mime_attachment*) CTX;
986 if (mime->Renderer != NULL)
987 mime->Renderer->f(mime, NULL, NULL);
988 StrBufAppendTemplate(Target, TP, mime->Data, 0);
989 /* TODO: check whether we need to load it now? */
992 void tmplput_MIME_LoadData(StrBuf *Target, WCTemplputParams *TP)
995 wc_mime_attachment *mime = (wc_mime_attachment*) CTX;
996 wc_mime_attachment *att;
998 if ( (!strcasecmp(ChrPtr(mime->Disposition), "inline"))||
999 (!strcasecmp(ChrPtr(mime->Disposition), "attachment")) )
1004 /* steal this mime part... */
1005 att = malloc(sizeof(wc_mime_attachment));
1006 memcpy(att, mime, sizeof(wc_mime_attachment));
1007 memset(mime, 0, sizeof(wc_mime_attachment));
1009 if (att->Data == NULL)
1012 if (WCC->attachments == NULL)
1013 WCC->attachments = NewHash(1, NULL);
1014 /* And add it to the list. */
1015 n = snprintf(N, sizeof N, "%d", GetCount(WCC->attachments) + 1);
1016 Put(WCC->attachments, N, n, att, DestroyMime);
1020 void tmplput_MIME_Length(StrBuf *Target, WCTemplputParams *TP)
1022 wc_mime_attachment *mime = (wc_mime_attachment*) CTX;
1023 StrBufAppendPrintf(Target, "%ld", mime->length);
1026 HashList *iterate_get_registered_Attachments(StrBuf *Target, WCTemplputParams *TP)
1028 return WC->attachments;
1031 void servcmd_do_search(char *buf, long bufsize)
1033 snprintf(buf, bufsize, "MSGS SEARCH|%s", bstr("query"));
1036 void servcmd_headers(char *buf, long bufsize)
1038 snprintf(buf, bufsize, "MSGS ALL");
1041 void servcmd_readfwd(char *buf, long bufsize)
1043 snprintf(buf, bufsize, "MSGS ALL");
1046 void servcmd_readnew(char *buf, long bufsize)
1048 snprintf(buf, bufsize, "MSGS NEW");
1051 void servcmd_readold(char *buf, long bufsize)
1053 snprintf(buf, bufsize, "MSGS OLD");
1057 readloop_struct rlid[] = {
1058 { {HKEY("do_search")}, servcmd_do_search},
1059 { {HKEY("headers")}, servcmd_headers},
1060 { {HKEY("readfwd")}, servcmd_readfwd},
1061 { {HKEY("readnew")}, servcmd_readnew},
1062 { {HKEY("readold")}, servcmd_readold}
1067 void SetAccessCommand(long Oper)
1069 wcsession *WCC = WC;
1071 if (WCC->UrlFragment1 != NULL ) {
1072 FlushStrBuf(WCC->UrlFragment1);
1073 StrBufAppendBufPlain(WCC->UrlFragment1,
1074 rlid[Oper].name.Key, rlid[Oper].name.len, 0);
1077 WCC->UrlFragment1 = NewStrBufPlain(rlid[Oper].name.Key, rlid[Oper].name.len);
1085 InitModule_MSGRENDERERS
1088 RegisterSortFunc(HKEY("date"),
1094 RegisterSortFunc(HKEY("subject"),
1100 RegisterSortFunc(HKEY("sender"),
1107 /* iterate over all known mails in WC->summ */
1108 RegisterIterator("MAIL:SUMM:MSGS", 0, NULL, iterate_get_mailsumm_All,
1109 NULL,NULL, CTX_MAILSUM, CTX_NONE, IT_NOFLAG);
1111 RegisterNamespace("MAIL:SUMM:DATEBRIEF", 0, 0, tmplput_MAIL_SUMM_DATE_BRIEF, CTX_MAILSUM);
1112 RegisterNamespace("MAIL:SUMM:DATEFULL", 0, 0, tmplput_MAIL_SUMM_DATE_FULL, CTX_MAILSUM);
1113 RegisterNamespace("MAIL:SUMM:DATENO", 0, 0, tmplput_MAIL_SUMM_DATE_NO, CTX_MAILSUM);
1114 RegisterNamespace("MAIL:SUMM:N", 0, 0, tmplput_MAIL_SUMM_N, CTX_MAILSUM);
1115 RegisterNamespace("MAIL:SUMM:FROM", 0, 2, tmplput_MAIL_SUMM_FROM, CTX_MAILSUM);
1116 RegisterNamespace("MAIL:SUMM:TO", 0, 2, tmplput_MAIL_SUMM_TO, CTX_MAILSUM);
1117 RegisterNamespace("MAIL:SUMM:SUBJECT", 0, 4, tmplput_MAIL_SUMM_SUBJECT, CTX_MAILSUM);
1118 RegisterNamespace("MAIL:SUMM:NTATACH", 0, 0, tmplput_MAIL_SUMM_NATTACH, CTX_MAILSUM);
1119 RegisterNamespace("MAIL:SUMM:CCCC", 0, 2, tmplput_MAIL_SUMM_CCCC, CTX_MAILSUM);
1120 RegisterNamespace("MAIL:SUMM:H_NODE", 0, 2, tmplput_MAIL_SUMM_H_NODE, CTX_MAILSUM);
1121 RegisterNamespace("MAIL:SUMM:ALLRCPT", 0, 2, tmplput_MAIL_SUMM_ALLRCPT, CTX_MAILSUM);
1122 RegisterNamespace("MAIL:SUMM:ORGROOM", 0, 2, tmplput_MAIL_SUMM_ORGROOM, CTX_MAILSUM);
1123 RegisterNamespace("MAIL:SUMM:RFCA", 0, 2, tmplput_MAIL_SUMM_RFCA, CTX_MAILSUM);
1124 RegisterNamespace("MAIL:SUMM:OTHERNODE", 2, 0, tmplput_MAIL_SUMM_OTHERNODE, CTX_MAILSUM);
1125 RegisterNamespace("MAIL:SUMM:REFIDS", 0, 0, tmplput_MAIL_SUMM_REFIDS, CTX_MAILSUM);
1126 RegisterNamespace("MAIL:SUMM:INREPLYTO", 0, 2, tmplput_MAIL_SUMM_INREPLYTO, CTX_MAILSUM);
1127 RegisterNamespace("MAIL:BODY", 0, 2, tmplput_MAIL_BODY, CTX_MAILSUM);
1128 RegisterNamespace("MAIL:QUOTETEXT", 1, 2, tmplput_QUOTED_MAIL_BODY, CTX_NONE);
1129 RegisterConditional(HKEY("COND:ROOM:DISPLAYMSG"), 0, Conditional_ROOM_DISPLAY_MSG, CTX_MAILSUM);
1130 RegisterConditional(HKEY("COND:MAIL:SUMM:LASTMSG"), 0, Conditional_MAIL_SUMM_LASTMSG, CTX_MAILSUM);
1131 RegisterConditional(HKEY("COND:MAIL:SUMM:RFCA"), 0, Conditional_MAIL_SUMM_RFCA, CTX_MAILSUM);
1132 RegisterConditional(HKEY("COND:MAIL:SUMM:CCCC"), 0, Conditional_MAIL_SUMM_CCCC, CTX_MAILSUM);
1133 RegisterConditional(HKEY("COND:MAIL:SUMM:UNREAD"), 0, Conditional_MAIL_SUMM_UNREAD, CTX_MAILSUM);
1134 RegisterConditional(HKEY("COND:MAIL:SUMM:H_NODE"), 0, Conditional_MAIL_SUMM_H_NODE, CTX_MAILSUM);
1135 RegisterConditional(HKEY("COND:MAIL:SUMM:OTHERNODE"), 0, Conditional_MAIL_SUMM_OTHERNODE, CTX_MAILSUM);
1136 RegisterConditional(HKEY("COND:MAIL:ANON"), 0, Conditional_ANONYMOUS_MESSAGE, CTX_MAILSUM);
1139 /* do we have mimetypes to iterate over? */
1140 RegisterConditional(HKEY("COND:MAIL:MIME:ATTACH"), 0, Conditional_MAIL_MIME_ALL, CTX_MAILSUM);
1141 RegisterConditional(HKEY("COND:MAIL:MIME:ATTACH:SUBMESSAGES"), 0, Conditional_MAIL_MIME_SUBMESSAGES, CTX_MAILSUM);
1142 RegisterConditional(HKEY("COND:MAIL:MIME:ATTACH:LINKS"), 0, Conditional_MAIL_MIME_ATTACHLINKS, CTX_MAILSUM);
1143 RegisterConditional(HKEY("COND:MAIL:MIME:ATTACH:ATT"), 0, Conditional_MAIL_MIME_ATTACH, CTX_MAILSUM);
1144 RegisterIterator("MAIL:MIME:ATTACH", 0, NULL, iterate_get_mime_All,
1145 NULL, NULL, CTX_MIME_ATACH, CTX_MAILSUM, IT_NOFLAG);
1146 RegisterIterator("MAIL:MIME:ATTACH:SUBMESSAGES", 0, NULL, iterate_get_mime_Submessages,
1147 NULL, NULL, CTX_MIME_ATACH, CTX_MAILSUM, IT_NOFLAG);
1148 RegisterIterator("MAIL:MIME:ATTACH:LINKS", 0, NULL, iterate_get_mime_AttachLinks,
1149 NULL, NULL, CTX_MIME_ATACH, CTX_MAILSUM, IT_NOFLAG);
1150 RegisterIterator("MAIL:MIME:ATTACH:ATT", 0, NULL, iterate_get_mime_Attachments,
1151 NULL, NULL, CTX_MIME_ATACH, CTX_MAILSUM, IT_NOFLAG);
1153 /* Parts of a mime attachent */
1154 RegisterNamespace("MAIL:MIME:NAME", 0, 2, tmplput_MIME_Name, CTX_MIME_ATACH);
1155 RegisterNamespace("MAIL:MIME:FILENAME", 0, 2, tmplput_MIME_FileName, CTX_MIME_ATACH);
1156 RegisterNamespace("MAIL:MIME:PARTNUM", 0, 2, tmplput_MIME_PartNum, CTX_MIME_ATACH);
1157 RegisterNamespace("MAIL:MIME:MSGNUM", 0, 2, tmplput_MIME_MsgNum, CTX_MIME_ATACH);
1158 RegisterNamespace("MAIL:MIME:DISPOSITION", 0, 2, tmplput_MIME_Disposition, CTX_MIME_ATACH);
1159 RegisterNamespace("MAIL:MIME:CONTENTTYPE", 0, 2, tmplput_MIME_ContentType, CTX_MIME_ATACH);
1160 RegisterNamespace("MAIL:MIME:CHARSET", 0, 2, tmplput_MIME_Charset, CTX_MIME_ATACH);
1161 RegisterNamespace("MAIL:MIME:LENGTH", 0, 2, tmplput_MIME_Length, CTX_MIME_ATACH);
1162 RegisterNamespace("MAIL:MIME:DATA", 0, 2, tmplput_MIME_Data, CTX_MIME_ATACH);
1163 /* load the actual attachment into WC->attachments; no output!!! */
1164 RegisterNamespace("MAIL:MIME:LOADDATA", 0, 0, tmplput_MIME_LoadData, CTX_MIME_ATACH);
1166 /* iterate the WC->attachments; use the above tokens for their contents */
1167 RegisterIterator("MSG:ATTACHNAMES", 0, NULL, iterate_get_registered_Attachments,
1168 NULL, NULL, CTX_MIME_ATACH, CTX_NONE, IT_NOFLAG);
1170 /* mime renderers translate an attachment into webcit viewable html text */
1171 RegisterMimeRenderer(HKEY("message/rfc822"), render_MAIL);
1172 RegisterMimeRenderer(HKEY("text/x-vcard"), render_MIME_VCard);
1173 RegisterMimeRenderer(HKEY("text/vcard"), render_MIME_VCard);
1174 RegisterMimeRenderer(HKEY("text/calendar"), render_MIME_ICS);
1175 RegisterMimeRenderer(HKEY("application/ics"), render_MIME_ICS);
1176 RegisterMimeRenderer(HKEY("text/x-citadel-variformat"), render_MAIL_variformat);
1177 RegisterMimeRenderer(HKEY("text/plain"), render_MAIL_text_plain);
1178 RegisterMimeRenderer(HKEY("text"), render_MAIL_text_plain);
1179 RegisterMimeRenderer(HKEY("text/html"), render_MAIL_html);
1180 RegisterMimeRenderer(HKEY(""), render_MAIL_UNKNOWN);
1182 /* these headers are citserver replies to MSG4 and friends. one evaluator for each */
1183 RegisterMsgHdr(HKEY("nhdr"), examine_nhdr, 0);
1184 RegisterMsgHdr(HKEY("type"), examine_type, 0);
1185 RegisterMsgHdr(HKEY("from"), examine_from, 0);
1186 RegisterMsgHdr(HKEY("subj"), examine_subj, 0);
1187 RegisterMsgHdr(HKEY("msgn"), examine_msgn, 0);
1188 RegisterMsgHdr(HKEY("wefw"), examine_wefw, 0);
1189 RegisterMsgHdr(HKEY("cccc"), examine_cccc, 0);
1190 RegisterMsgHdr(HKEY("hnod"), examine_hnod, 0);
1191 RegisterMsgHdr(HKEY("room"), examine_room, 0);
1192 RegisterMsgHdr(HKEY("rfca"), examine_rfca, 0);
1193 RegisterMsgHdr(HKEY("node"), examine_node, 0);
1194 RegisterMsgHdr(HKEY("rcpt"), examine_rcpt, 0);
1195 RegisterMsgHdr(HKEY("time"), examine_time, 0);
1196 RegisterMsgHdr(HKEY("part"), examine_mime_part, 0);
1197 RegisterMsgHdr(HKEY("text"), examine_text, 1);
1198 /* these are the content-type headers we get infront of a message; put it into the same hash since it doesn't clash. */
1199 RegisterMsgHdr(HKEY("X-Citadel-MSG4-Partnum"), examine_msg4_partnum, 0);
1200 RegisterMsgHdr(HKEY("Content-type"), examine_content_type, 0);
1201 RegisterMsgHdr(HKEY("Content-length"), examine_content_lengh, 0);
1202 RegisterMsgHdr(HKEY("Content-transfer-encoding"), examine_content_encoding, 0); /* do we care? */
1203 RegisterMsgHdr(HKEY("charset"), examine_charset, 0);
1205 /* Don't care about these... */
1206 RegisterMsgHdr(HKEY("pref"), examine_pref, 0);
1207 RegisterMsgHdr(HKEY("suff"), examine_suff, 0);
1208 RegisterMsgHdr(HKEY("path"), examine_path, 0);