4 * Functions which deal with the fetching and displaying of messages.
12 HashList *MsgHeaderHandler = NULL;
13 HashList *MsgEvaluators = NULL;
14 HashList *MimeRenderHandler = NULL;
16 #define SUBJ_COL_WIDTH_PCT 50 /**< Mailbox view column width */
17 #define SENDER_COL_WIDTH_PCT 30 /**< Mailbox view column width */
18 #define DATE_PLUS_BUTTONS_WIDTH_PCT 20 /**< Mailbox view column width */
20 void display_enter(void);
21 int longcmp_r(const void *s1, const void *s2);
22 int summcmp_subj(const void *s1, const void *s2);
23 int summcmp_rsubj(const void *s1, const void *s2);
24 int summcmp_sender(const void *s1, const void *s2);
25 int summcmp_rsender(const void *s1, const void *s2);
26 int summcmp_date(const void *s1, const void *s2);
27 int summcmp_rdate(const void *s1, const void *s2);
29 /*----------------------------------------------------------------------------*/
32 typedef void (*MsgPartEvaluatorFunc)(message_summary *Sum, StrBuf *Buf);
42 typedef struct _headereval {
43 ExamineMsgHeaderFunc evaluator;
55 const char* SortIcons[3] = {
56 "static/up_pointer.gif",
57 "static/down_pointer.gif",
58 "static/sort_none.gif"
72 /* SortEnum to plain string representation */
73 static const char* SortByStrings[] = {
84 /* SortEnum to sort-Function Table */
85 const CompareFunc SortFuncs[eUnSet] = {
95 /* given a SortEnum, which icon should we choose? */
96 const int SortDateToIcon[eUnSet] = { eUp, eDown, eNone, eNone, eNone, eNone, eNone};
97 const int SortSubjectToIcon[eUnSet] = { eNone, eNone, eUp, eDown, eNone, eNone, eNone};
98 const int SortSenderToIcon[eUnSet] = { eNone, eNone, eNone, eNone, eUp, eDown, eNone};
100 /* given a SortEnum, which would be the "opposite" search option? */
101 const int DateInvertSortString[eUnSet] = { eRDate, eDate, eDate, eDate, eDate, eDate, eDate};
102 const int SubjectInvertSortString[eUnSet] = { eSubject, eSubject, eRSubject, eUnSet, eSubject, eSubject, eSubject};
103 const int SenderInvertSortString[eUnSet] = { eSender, eSender, eSender, eSender, eRSender, eUnSet, eSender};
109 * Address book entry (keep it short and sweet, it's just a quickie lookup
110 * which we can use to get to the real meat and bones later)
113 char ab_name[64]; /**< name string */
114 long ab_msgnum; /**< message number of address book entry */
117 /*----------------------------------------------------------------------------*/
120 * Translates sortoption String to its SortEnum representation
121 * returns the enum matching the string; defaults to RDate
124 int StrToESort (const StrBuf *sortby)
128 if (!IsEmptyStr(ChrPtr(sortby))) while (result < eUnSet){
129 if (!strcasecmp(ChrPtr(sortby),
130 SortByStrings[result]))
138 typedef int (*QSortFunction) (const void*, const void*);
141 * qsort() compatible function to compare two longs in descending order.
143 int longcmp_r(const void *s1, const void *s2) {
147 l1 = *(long *)GetSearchPayload(s1);
148 l2 = *(long *)GetSearchPayload(s2);
150 if (l1 > l2) return(-1);
151 if (l1 < l2) return(+1);
157 * qsort() compatible function to compare two message summary structs by ascending subject.
159 int summcmp_subj(const void *s1, const void *s2) {
160 message_summary *summ1;
161 message_summary *summ2;
163 summ1 = (message_summary *)GetSearchPayload(s1);
164 summ2 = (message_summary *)GetSearchPayload(s2);
165 return strcasecmp(ChrPtr(summ1->subj), ChrPtr(summ2->subj));
169 * qsort() compatible function to compare two message summary structs by descending subject.
171 int summcmp_rsubj(const void *s1, const void *s2) {
172 message_summary *summ1;
173 message_summary *summ2;
175 summ1 = (message_summary *)GetSearchPayload(s1);
176 summ2 = (message_summary *)GetSearchPayload(s2);
177 return strcasecmp(ChrPtr(summ2->subj), ChrPtr(summ1->subj));
181 * qsort() compatible function to compare two message summary structs by ascending sender.
183 int summcmp_sender(const void *s1, const void *s2) {
184 message_summary *summ1;
185 message_summary *summ2;
187 summ1 = (message_summary *)GetSearchPayload(s1);
188 summ2 = (message_summary *)GetSearchPayload(s2);
189 return strcasecmp(ChrPtr(summ1->from), ChrPtr(summ2->from));
193 * qsort() compatible function to compare two message summary structs by descending sender.
195 int summcmp_rsender(const void *s1, const void *s2) {
196 message_summary *summ1;
197 message_summary *summ2;
199 summ1 = (message_summary *)GetSearchPayload(s1);
200 summ2 = (message_summary *)GetSearchPayload(s2);
201 return strcasecmp(ChrPtr(summ2->from), ChrPtr(summ1->from));
205 * qsort() compatible function to compare two message summary structs by ascending date.
207 int summcmp_date(const void *s1, const void *s2) {
208 message_summary *summ1;
209 message_summary *summ2;
211 summ1 = (message_summary *)GetSearchPayload(s1);
212 summ2 = (message_summary *)GetSearchPayload(s2);
214 if (summ1->date < summ2->date) return -1;
215 else if (summ1->date > summ2->date) return +1;
220 * qsort() compatible function to compare two message summary structs by descending date.
222 int summcmp_rdate(const void *s1, const void *s2) {
223 message_summary *summ1;
224 message_summary *summ2;
226 summ1 = (message_summary *)GetSearchPayload(s1);
227 summ2 = (message_summary *)GetSearchPayload(s2);
229 if (summ1->date < summ2->date) return +1;
230 else if (summ1->date > summ2->date) return -1;
238 /*----------------------------------------------------------------------------*/
241 * message index functions
247 void DestroyMessageSummary(void *vMsg)
249 message_summary *Msg = (message_summary*) vMsg;
251 FreeStrBuf(&Msg->from);
252 FreeStrBuf(&Msg->to);
253 FreeStrBuf(&Msg->subj);
254 FreeStrBuf(&Msg->reply_inreplyto);
255 FreeStrBuf(&Msg->reply_references);
256 FreeStrBuf(&Msg->cccc);
257 FreeStrBuf(&Msg->hnod);
258 FreeStrBuf(&Msg->AllRcpt);
259 FreeStrBuf(&Msg->Room);
260 FreeStrBuf(&Msg->Rfca);
261 FreeStrBuf(&Msg->OtherNode);
268 void RegisterMsgHdr(const char *HeaderName, long HdrNLen, ExamineMsgHeaderFunc evaluator, int type)
271 ev = (headereval*) malloc(sizeof(headereval));
272 ev->evaluator = evaluator;
274 Put(MsgHeaderHandler, HeaderName, HdrNLen, ev, NULL);
277 void RegisterMimeRenderer(const char *HeaderName, long HdrNLen, RenderMimeFunc MimeRenderer)
279 Put(MimeRenderHandler, HeaderName, HdrNLen, MimeRenderer, reference_free_handler);
283 /*----------------------------------------------------------------------------*/
286 void examine_nhdr(message_summary *Msg, StrBuf *HdrLine)
289 if (!strncasecmp(ChrPtr(HdrLine), "yes", 8))
293 void examine_type(message_summary *Msg, StrBuf *HdrLine)
295 Msg->format_type = StrToi(HdrLine);
299 void examine_from(message_summary *Msg, StrBuf *HdrLine)
301 FreeStrBuf(&Msg->from);
302 Msg->from = NewStrBufPlain(NULL, StrLength(HdrLine));
303 StrBuf_RFC822_to_Utf8(Msg->from, HdrLine, WC->DefaultCharset);
305 void tmplput_MAIL_SUMM_FROM(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
307 message_summary *Msg = (message_summary*) Context;
308 StrBufAppendBuf(Target, Msg->from, 0);
309 lprintf(1,"%s", ChrPtr(Msg->from));
314 void examine_subj(message_summary *Msg, StrBuf *HdrLine)
316 FreeStrBuf(&Msg->subj);
317 Msg->subj = NewStrBufPlain(NULL, StrLength(HdrLine));
318 StrBuf_RFC822_to_Utf8(Msg->subj, HdrLine, WC->DefaultCharset);
319 lprintf(1,"%s", ChrPtr(Msg->subj));
321 void tmplput_MAIL_SUMM_SUBJECT(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
322 {/////TODO: Fwd: and RE: filter!!
323 message_summary *Msg = (message_summary*) Context;
324 StrBufAppendBuf(Target, Msg->subj, 0);
328 void examine_msgn(message_summary *Msg, StrBuf *HdrLine)
330 FreeStrBuf(&Msg->reply_inreplyto);
331 Msg->reply_inreplyto = NewStrBufPlain(NULL, StrLength(HdrLine));
332 StrBuf_RFC822_to_Utf8(Msg->reply_inreplyto, HdrLine, WC->DefaultCharset);
334 void tmplput_MAIL_SUMM_INREPLYTO(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
336 message_summary *Msg = (message_summary*) Context;
337 StrBufAppendBuf(Target, Msg->reply_inreplyto, 0);
341 void examine_wefw(message_summary *Msg, StrBuf *HdrLine)
343 FreeStrBuf(&Msg->reply_references);
344 Msg->reply_references = NewStrBufPlain(NULL, StrLength(HdrLine));
345 StrBuf_RFC822_to_Utf8(Msg->reply_references, HdrLine, WC->DefaultCharset);
347 void tmplput_MAIL_SUMM_REFIDS(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
349 message_summary *Msg = (message_summary*) Context;
350 StrBufAppendBuf(Target, Msg->reply_references, 0);
354 void examine_cccc(message_summary *Msg, StrBuf *HdrLine)
356 FreeStrBuf(&Msg->cccc);
357 Msg->cccc = NewStrBufPlain(NULL, StrLength(HdrLine));
358 StrBuf_RFC822_to_Utf8(Msg->cccc, HdrLine, WC->DefaultCharset);
359 if (Msg->AllRcpt == NULL)
360 Msg->AllRcpt = NewStrBufPlain(NULL, StrLength(HdrLine));
361 if (StrLength(Msg->AllRcpt) > 0) {
362 StrBufAppendBufPlain(Msg->AllRcpt, HKEY(", "), 0);
364 StrBufAppendBuf(Msg->AllRcpt, Msg->cccc, 0);
366 void tmplput_MAIL_SUMM_CCCC(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
368 message_summary *Msg = (message_summary*) Context;
369 StrBufAppendBuf(Target, Msg->cccc, 0);
375 void examine_room(message_summary *Msg, StrBuf *HdrLine)
377 if ((StrLength(HdrLine) > 0) &&
378 (strcasecmp(ChrPtr(HdrLine), WC->wc_roomname))) {
379 FreeStrBuf(&Msg->Room);
380 Msg->Room = NewStrBufDup(HdrLine);
383 void tmplput_MAIL_SUMM_ORGROOM(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
385 message_summary *Msg = (message_summary*) Context;
386 StrBufAppendBuf(Target, Msg->Room, 0);
390 void examine_rfca(message_summary *Msg, StrBuf *HdrLine)
392 FreeStrBuf(&Msg->Rfca);
393 Msg->Rfca = NewStrBufDup(HdrLine);
395 void tmplput_MAIL_SUMM_RFCA(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
397 message_summary *Msg = (message_summary*) Context;
398 StrBufAppendBuf(Target, Msg->Rfca, 0);
402 void examine_node(message_summary *Msg, StrBuf *HdrLine)
404 if ( (StrLength(HdrLine) > 0) &&
405 ((WC->room_flags & QR_NETWORK)
406 || ((strcasecmp(ChrPtr(HdrLine), serv_info.serv_nodename)
407 && (strcasecmp(ChrPtr(HdrLine), serv_info.serv_fqdn)))))) {
408 FreeStrBuf(&Msg->OtherNode);
409 Msg->OtherNode = NewStrBufDup(HdrLine);
412 void tmplput_MAIL_SUMM_OTHERNODE(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
414 message_summary *Msg = (message_summary*) Context;
415 StrBufAppendBuf(Target, Msg->OtherNode, 0);
417 int Conditional_MAIL_SUMM_OTHERNODE(WCTemplateToken *Tokens, void *Context, int ContextType)
419 message_summary *Msg = (message_summary*) Context;
420 return StrLength(Msg->OtherNode) > 0;
424 void examine_rcpt(message_summary *Msg, StrBuf *HdrLine)
426 FreeStrBuf(&Msg->to);
427 Msg->to = NewStrBufPlain(NULL, StrLength(HdrLine));
428 StrBuf_RFC822_to_Utf8(Msg->to, HdrLine, WC->DefaultCharset);
429 if (Msg->AllRcpt == NULL)
430 Msg->AllRcpt = NewStrBufPlain(NULL, StrLength(HdrLine));
431 if (StrLength(Msg->AllRcpt) > 0) {
432 StrBufAppendBufPlain(Msg->AllRcpt, HKEY(", "), 0);
434 StrBufAppendBuf(Msg->AllRcpt, Msg->to, 0);
436 void tmplput_MAIL_SUMM_TO(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
438 message_summary *Msg = (message_summary*) Context;
439 StrBufAppendBuf(Target, Msg->to, 0);
441 void tmplput_MAIL_SUMM_ALLRCPT(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
443 message_summary *Msg = (message_summary*) Context;
444 StrBufAppendBuf(Target, Msg->AllRcpt, 0);
449 void examine_time(message_summary *Msg, StrBuf *HdrLine)
451 Msg->date = StrTol(HdrLine);
453 void tmplput_MAIL_SUMM_DATE_STR(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
456 message_summary *Msg = (message_summary*) Context;
457 webcit_fmt_date(datebuf, Msg->date, 1);
458 StrBufAppendBufPlain(Target, datebuf, -1, 0);
460 void tmplput_MAIL_SUMM_DATE_NO(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
462 message_summary *Msg = (message_summary*) Context;
463 StrBufAppendPrintf(Target, "%ld", Msg->date, 0);
468 void examine_mime_part(message_summary *Msg, StrBuf *HdrLine)
470 wc_mime_attachment *mime;
473 mime = (wc_mime_attachment*) malloc(sizeof(wc_mime_attachment));
474 memset(mime, 0, sizeof(wc_mime_attachment));
477 mime->Name = NewStrBuf();
478 StrBufExtract_token(mime->Name, HdrLine, 0, '|');
479 StrBufExtract_token(Buf, HdrLine, 1, '|');
480 StrBuf_RFC822_to_Utf8(mime->FileName, Buf, WC->DefaultCharset);
481 mime->PartNum = NewStrBuf();
482 StrBufExtract_token(mime->PartNum, HdrLine, 2, '|');
483 mime->Disposition = NewStrBuf();
484 StrBufExtract_token(mime->Disposition, HdrLine, 3, '|');
485 mime->ContentType = NewStrBuf();
486 StrBufExtract_token(mime->ContentType, HdrLine, 4, '|');
487 mime->length = StrBufExtract_int(HdrLine, 5, '|');
489 StrBufTrim(mime->Name);
490 StrBufTrim(mime->FileName);
491 if ( (StrLength(mime->FileName) == 0) && (StrLength(mime->Name) > 0) ) {
492 StrBufAppendBuf(mime->FileName, mime->Name, 0);
495 if (!strcasecmp(ChrPtr(mime->ContentType), "message/rfc822")) {
496 if (Msg->Submessages == NULL)
497 Msg->Submessages = NewHash(1,NULL);
498 Put(Msg->Submessages, SKEY(mime->PartNum), mime->PartNum, reference_free_handler);
500 else if ((!strcasecmp(ChrPtr(mime->Disposition), "inline"))
501 && (!strncasecmp(ChrPtr(mime->ContentType), "image/", 6)) ){
502 if (Msg->AttachLinks == NULL)
503 Msg->AttachLinks = NewHash(1,NULL);
504 Put(Msg->AttachLinks, SKEY(mime->PartNum), mime->PartNum, reference_free_handler);
506 else if ((StrLength(mime->ContentType) > 0) &&
507 ( (!strcasecmp(ChrPtr(mime->Disposition), "attachment"))
508 || (!strcasecmp(ChrPtr(mime->Disposition), "inline"))
509 || (!strcasecmp(ChrPtr(mime->Disposition), ""))))
512 if (Msg->AttachLinks == NULL)
513 Msg->AttachLinks = NewHash(1,NULL);
514 Put(Msg->AttachLinks, SKEY(mime->PartNum), mime->PartNum, reference_free_handler);
515 if (strcasecmp(ChrPtr(mime->ContentType), "application/octet-stream") == 0) {
516 FlushStrBuf(mime->ContentType);
517 StrBufAppendBufPlain(mime->ContentType,
518 GuessMimeByFilename(SKEY(mime->FileName)),
523 /** begin handler prep ** */
524 if ( (!strcasecmp(ChrPtr(mime->ContentType), "text/x-vcard"))
525 || (!strcasecmp(ChrPtr(mime->ContentType), "text/vcard")) ) {
526 Msg->vcard_partnum_ref = mime;
528 else if ( (!strcasecmp(ChrPtr(mime->ContentType), "text/calendar"))
529 || (!strcasecmp(ChrPtr(mime->ContentType), "application/ics")) ) {
530 Msg->cal_partnum_ref = mime;
532 /** end handler prep ***/
534 void tmplput_MAIL_SUMM_NATTACH(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
536 message_summary *Msg = (message_summary*) Context;
537 StrBufAppendPrintf(Target, "%ld", GetCount(Msg->Attachments));
546 void examine_hnod(message_summary *Msg, StrBuf *HdrLine)
548 FreeStrBuf(&Msg->hnod);
549 Msg->hnod = NewStrBufPlain(NULL, StrLength(HdrLine));
550 StrBuf_RFC822_to_Utf8(Msg->hnod, HdrLine, WC->DefaultCharset);
552 void tmplput_MAIL_SUMM_H_NODE(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
554 message_summary *Msg = (message_summary*) Context;
555 StrBufAppendBuf(Target, Msg->hnod, 0);
557 int Conditional_MAIL_SUMM_H_NODE(WCTemplateToken *Tokens, void *Context, int ContextType)
559 message_summary *Msg = (message_summary*) Context;
560 return StrLength(Msg->hnod) > 0;
565 void examine_text(message_summary *Msg, StrBuf *HdrLine)
566 {////TODO: read messages here
567 Msg->MsgBody.Data = NewStrBuf();
570 void examine_msg4_partnum(message_summary *Msg, StrBuf *HdrLine)
572 Msg->MsgBody.PartNum = NewStrBufDup(HdrLine);
573 StrBufTrim(Msg->MsgBody.PartNum);/////TODO: striplt == trim?
576 void examine_content_encoding(message_summary *Msg, StrBuf *HdrLine)
578 ////TODO: do we care?
581 void examine_content_lengh(message_summary *Msg, StrBuf *HdrLine)
583 Msg->MsgBody.length = StrTol(HdrLine);
586 void examine_content_type(message_summary *Msg, StrBuf *HdrLine)
589 Msg->MsgBody.ContentType = NewStrBufDup(HdrLine);
590 StrBufTrim(Msg->MsgBody.ContentType);/////todo==striplt?
591 len = StrLength(Msg->MsgBody.ContentType);
592 for (i=0; i<len; ++i) {
593 if (!strncasecmp(ChrPtr(Msg->MsgBody.ContentType) + i, "charset=", 8)) {/// TODO: WHUT?
594 // safestrncpy(mime_charset, &mime_content_type[i+8],
595 /// sizeof mime_charset);
598 for (i=0; i<len; ++i) {
599 if (mime_content_type[i] == ';') {
600 mime_content_type[i] = 0;
604 len = strlen(mime_charset);
605 for (i=0; i<len; ++i) {
606 if (mime_charset[i] == ';') {
614 void tmplput_MAIL_SUMM_N(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
616 message_summary *Msg = (message_summary*) Context;
617 StrBufAppendPrintf(Target, "%ld", Msg->msgnum);
621 int Conditional_MAIL_SUMM_UNREAD(WCTemplateToken *Tokens, void *Context, int ContextType)
623 message_summary *Msg = (message_summary*) Context;
624 return Msg->is_new != 0;
629 /*----------------------------------------------------------------------------*/
632 void tmplput_MAIL_BODY(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
634 message_summary *Msg = (message_summary*) Context;
635 StrBufAppendBuf(Target, Msg->MsgBody.Data, 0);
639 void render_MAIL_variformat(wc_mime_attachment *Mime, StrBuf *RawData)
641 /* Messages in legacy Citadel variformat get handled thusly... */
642 fmout("JUSTIFY");///todo: this won't work that way.
646 void render_MAIL_text_plain(wc_mime_attachment *Mime, StrBuf *RawData)
648 const char *ptr, *pte;
649 const char *BufPtr = NULL;
650 StrBuf *Line = NewStrBuf();
651 StrBuf *Line1 = NewStrBuf();
652 StrBuf *Line2 = NewStrBuf();
653 StrBuf *Target = NewStrBufPlain(NULL, StrLength(Mime->Data));
660 iconv_t ic = (iconv_t)(-1) ;
663 /* Boring old 80-column fixed format text gets handled this way... */
664 if ((strcasecmp(ChrPtr(Mime->Charset), "us-ascii") == 0) &&
665 (strcasecmp(ChrPtr(Mime->Charset), "UTF-8") == 0))
670 ctdl_iconv_open("UTF-8", ChrPtr(Mime->Charset), &ic);
671 if (ic == (iconv_t)(-1) ) {
672 lprintf(5, "%s:%d iconv_open(UTF-8, %s) failed: %s\n",
673 __FILE__, __LINE__, ChrPtr(Mime->Charset), strerror(errno));
678 while (StrBufSipLine(Line, Mime->Data, &BufPtr) > 0)
684 len = StrLength(Line);
687 while ((ptr < pte) &&
696 if (i > 0) StrBufCutLeft(Line, i);
698 if (StrLength(Line) == 0)
701 for (i = bn; i < bq; i++)
702 StrBufAppendBufPlain(Target, HKEY("<blockquote>"), 0);
703 for (i = bq; i < bn; i++)
704 StrBufAppendBufPlain(Target, HKEY("</blockquote>"), 0);
706 StrBufAppendBufPlain(Target, HKEY("<tt>"), 0);
707 UrlizeText(Line1, Line, Line2);
709 StrEscAppend(Target, Line1, NULL, 0, 0);
710 StrBufAppendBufPlain(Target, HKEY("</tt><br />\n"), 0);
714 for (i = bq; i < bn; i++)
715 StrBufAppendBufPlain(Target, HKEY("</blockquote>"), 0);
717 StrBufAppendBufPlain(Target, HKEY("</i><br />"), 0);
719 if (ic != (iconv_t)(-1) ) {
723 FreeStrBuf(&Mime->Data);
728 void render_MAIL_html(wc_mime_attachment *Mime, StrBuf *RawData)
731 /* HTML is fun, but we've got to strip it first */
732 Buf = NewStrBufPlain(NULL, StrLength(Mime->Data));
733 output_html(ChrPtr(Mime->Charset),
734 (WC->wc_view == VIEW_WIKI ? 1 : 0),
735 StrToi(Mime->PartNum),
737 FreeStrBuf(&Mime->Data);
741 void render_MAIL_UNKNOWN(wc_mime_attachment *Mime, StrBuf *RawData)
743 /* Unknown weirdness */
744 //// wprintf(_("I don't know how to display %s"), Msg->MsgBody->ContentType);
755 * Look for URL's embedded in a buffer and make them linkable. We use a
756 * target window in order to keep the Citadel session in its own window.
758 void UrlizeText(StrBuf* Target, StrBuf *Source, StrBuf *WrkBuf)
760 int len, UrlLen, Offset, TrailerLen;
761 const char *start, *end, *pos;
766 len = StrLength(Source);
767 end = ChrPtr(Source) + len;
768 for (pos = ChrPtr(Source); (pos < end) && (start == NULL); ++pos) {
769 if (!strncasecmp(pos, "http://", 7))
771 if (!strncasecmp(pos, "ftp://", 6))
776 StrBufAppendBuf(Target, Source, 0);
781 for (pos = ChrPtr(Source) + len; pos > start; --pos) {
782 if ( (!isprint(*pos))
801 UrlLen = end - start;
802 StrBufAppendBufPlain(WrkBuf, start, UrlLen, 0);
804 Offset = start - ChrPtr(Source);
806 StrBufAppendBufPlain(Target, ChrPtr(Source), Offset, 0);
807 StrBufAppendPrintf(Target, "%ca href=%c%s%c TARGET=%c%s%c%c%s%c/A%c",
808 LB, QU, ChrPtr(WrkBuf), QU, QU, TARGET,
809 QU, RB, ChrPtr(WrkBuf), LB, RB);
811 TrailerLen = len - (end - start);
813 StrBufAppendBufPlain(Target, end, TrailerLen, 0);
815 void url(char *buf, size_t bufsize)
817 int len, UrlLen, Offset, TrailerLen, outpos;
818 char *start, *end, *pos;
825 lprintf(1, "URL: content longer than buffer!");
829 for (pos = buf; (pos < end) && (start == NULL); ++pos) {
830 if (!strncasecmp(pos, "http://", 7))
832 if (!strncasecmp(pos, "ftp://", 6))
839 for (pos = buf+len; pos > start; --pos) {
840 if ( (!isprint(*pos))
859 UrlLen = end - start;
860 if (UrlLen > sizeof(urlbuf)){
861 lprintf(1, "URL: content longer than buffer!");
864 memcpy(urlbuf, start, UrlLen);
865 urlbuf[UrlLen] = '\0';
867 Offset = start - buf;
868 if ((Offset != 0) && (Offset < sizeof(outbuf)))
869 memcpy(outbuf, buf, Offset);
870 outpos = snprintf(&outbuf[Offset], sizeof(outbuf) - Offset,
871 "%ca href=%c%s%c TARGET=%c%s%c%c%s%c/A%c",
872 LB, QU, urlbuf, QU, QU, TARGET, QU, RB, urlbuf, LB, RB);
873 if (outpos >= sizeof(outbuf) - Offset) {
874 lprintf(1, "URL: content longer than buffer!");
878 TrailerLen = len - (end - start);
880 memcpy(outbuf + Offset + outpos, end, TrailerLen);
881 if (Offset + outpos + TrailerLen > bufsize) {
882 lprintf(1, "URL: content longer than buffer!");
885 memcpy (buf, outbuf, Offset + outpos + TrailerLen);
886 *(buf + Offset + outpos + TrailerLen) = '\0';
891 * \brief Turn a vCard "n" (name) field into something displayable.
892 * \param name the name field to convert
894 void vcard_n_prettyize(char *name)
899 original_name = strdup(name);
900 len = strlen(original_name);
901 for (i=0; i<5; ++i) {
903 if (original_name[len-1] == ' ') {
904 original_name[--len] = 0;
906 if (original_name[len-1] == ';') {
907 original_name[--len] = 0;
913 for (i=0; i<len; ++i) {
914 if (original_name[i] == ';') {
919 name[j++] = original_name[i];
930 * \brief preparse a vcard name
931 * display_vcard() calls this after parsing the textual vCard into
932 * our 'struct vCard' data object.
933 * This gets called instead of display_parsed_vcard() if we are only looking
934 * to extract the person's name instead of displaying the card.
935 * \param v the vcard to retrieve the name from
936 * \param storename where to put the name at
938 void fetchname_parsed_vcard(struct vCard *v, char *storename) {
941 strcpy(storename, "");
943 name = vcard_get_prop(v, "n", 1, 0, 0);
945 strcpy(storename, name);
946 /* vcard_n_prettyize(storename); */
954 * \brief html print a vcard
955 * display_vcard() calls this after parsing the textual vCard into
956 * our 'struct vCard' data object.
958 * Set 'full' to nonzero to display the full card, otherwise it will only
959 * show a summary line.
961 * This code is a bit ugly, so perhaps an explanation is due: we do this
962 * in two passes through the vCard fields. On the first pass, we process
963 * fields we understand, and then render them in a pretty fashion at the
964 * end. Then we make a second pass, outputting all the fields we don't
965 * understand in a simple two-column name/value format.
966 * \param v the vCard to display
967 * \param full display all items of the vcard?
968 * \param msgnum Citadel message pointer
970 void display_parsed_vcard(struct vCard *v, int full, long msgnum) {
976 char *thisname, *thisvalue;
977 char firsttoken[SIZ];
986 strcpy(fullname, "");
994 name = vcard_get_prop(v, "fn", 1, 0, 0);
998 else if (name = vcard_get_prop(v, "n", 1, 0, 0), name != NULL) {
999 strcpy(fullname, name);
1000 vcard_n_prettyize(fullname);
1010 wprintf("<div align=center>"
1011 "<table bgcolor=#aaaaaa width=50%%>");
1012 for (pass=1; pass<=2; ++pass) {
1014 if (v->numprops) for (i=0; i<(v->numprops); ++i) {
1016 thisname = strdup(v->prop[i].name);
1017 extract_token(firsttoken, thisname, 0, ';', sizeof firsttoken);
1019 for (j=0; j<num_tokens(thisname, ';'); ++j) {
1020 extract_token(buf, thisname, j, ';', sizeof buf);
1021 if (!strcasecmp(buf, "encoding=quoted-printable")) {
1023 remove_token(thisname, j, ';');
1025 if (!strcasecmp(buf, "encoding=base64")) {
1027 remove_token(thisname, j, ';');
1031 len = strlen(v->prop[i].value);
1032 /* if we have some untagged QP, detect it here. */
1033 if (!is_qp && (strstr(v->prop[i].value, "=?")!=NULL))
1034 utf8ify_rfc822_string(v->prop[i].value);
1037 // %ff can become 6 bytes in utf8
1038 thisvalue = malloc(len * 2 + 3);
1039 j = CtdlDecodeQuotedPrintable(
1040 thisvalue, v->prop[i].value,
1045 // ff will become one byte..
1046 thisvalue = malloc(len + 50);
1048 thisvalue, v->prop[i].value,
1049 strlen(v->prop[i].value) );
1052 thisvalue = strdup(v->prop[i].value);
1055 /** Various fields we may encounter ***/
1057 /** N is name, but only if there's no FN already there */
1058 if (!strcasecmp(firsttoken, "n")) {
1059 if (IsEmptyStr(fullname)) {
1060 strcpy(fullname, thisvalue);
1061 vcard_n_prettyize(fullname);
1065 /** FN (full name) is a true 'display name' field */
1066 else if (!strcasecmp(firsttoken, "fn")) {
1067 strcpy(fullname, thisvalue);
1071 else if (!strcasecmp(firsttoken, "title")) {
1072 strcpy(title, thisvalue);
1076 else if (!strcasecmp(firsttoken, "org")) {
1077 strcpy(org, thisvalue);
1080 else if (!strcasecmp(firsttoken, "email")) {
1082 if (!IsEmptyStr(mailto)) strcat(mailto, "<br />");
1084 "<a href=\"display_enter"
1085 "?force_room=_MAIL_?recp=");
1087 len = strlen(mailto);
1088 urlesc(&mailto[len], SIZ - len, "\"");
1089 len = strlen(mailto);
1090 urlesc(&mailto[len], SIZ - len, fullname);
1091 len = strlen(mailto);
1092 urlesc(&mailto[len], SIZ - len, "\" <");
1093 len = strlen(mailto);
1094 urlesc(&mailto[len], SIZ - len, thisvalue);
1095 len = strlen(mailto);
1096 urlesc(&mailto[len], SIZ - len, ">");
1098 strcat(mailto, "\">");
1099 len = strlen(mailto);
1100 stresc(mailto+len, SIZ - len, thisvalue, 1, 1);
1101 strcat(mailto, "</A>");
1103 else if (!strcasecmp(firsttoken, "tel")) {
1104 if (!IsEmptyStr(phone)) strcat(phone, "<br />");
1105 strcat(phone, thisvalue);
1106 for (j=0; j<num_tokens(thisname, ';'); ++j) {
1107 extract_token(buf, thisname, j, ';', sizeof buf);
1108 if (!strcasecmp(buf, "tel"))
1110 else if (!strcasecmp(buf, "work"))
1111 strcat(phone, _(" (work)"));
1112 else if (!strcasecmp(buf, "home"))
1113 strcat(phone, _(" (home)"));
1114 else if (!strcasecmp(buf, "cell"))
1115 strcat(phone, _(" (cell)"));
1117 strcat(phone, " (");
1123 else if (!strcasecmp(firsttoken, "adr")) {
1125 wprintf("<TR><TD>");
1126 wprintf(_("Address:"));
1127 wprintf("</TD><TD>");
1128 for (j=0; j<num_tokens(thisvalue, ';'); ++j) {
1129 extract_token(buf, thisvalue, j, ';', sizeof buf);
1130 if (!IsEmptyStr(buf)) {
1132 if (j<3) wprintf("<br />");
1136 wprintf("</TD></TR>\n");
1139 /* else if (!strcasecmp(firsttoken, "photo") && full && pass == 2) {
1140 // Only output on second pass
1141 wprintf("<tr><td>");
1142 wprintf(_("Photo:"));
1143 wprintf("</td><td>");
1144 wprintf("<img src=\"/vcardphoto/%ld/\" alt=\"Contact photo\"/>",msgnum);
1145 wprintf("</td></tr>\n");
1147 else if (!strcasecmp(firsttoken, "version")) {
1150 else if (!strcasecmp(firsttoken, "rev")) {
1153 else if (!strcasecmp(firsttoken, "label")) {
1158 /*** Don't show extra fields. They're ugly.
1160 wprintf("<TR><TD>");
1162 wprintf("</TD><TD>");
1164 wprintf("</TD></TR>\n");
1174 wprintf("<TR BGCOLOR=\"#AAAAAA\">"
1175 "<TD COLSPAN=2 BGCOLOR=\"#FFFFFF\">"
1176 "<IMG ALIGN=CENTER src=\"static/viewcontacts_48x.gif\">"
1177 "<FONT SIZE=+1><B>");
1179 wprintf("</B></FONT>");
1180 if (!IsEmptyStr(title)) {
1181 wprintf("<div align=right>");
1185 if (!IsEmptyStr(org)) {
1186 wprintf("<div align=right>");
1190 wprintf("</TD></TR>\n");
1192 if (!IsEmptyStr(phone)) {
1193 wprintf("<tr><td>");
1194 wprintf(_("Telephone:"));
1195 wprintf("</td><td>%s</td></tr>\n", phone);
1197 if (!IsEmptyStr(mailto)) {
1198 wprintf("<tr><td>");
1199 wprintf(_("E-mail:"));
1200 wprintf("</td><td>%s</td></tr>\n", mailto);
1206 wprintf("</table></div>\n");
1212 * \brief Display a textual vCard
1213 * (Converts to a vCard object and then calls the actual display function)
1214 * Set 'full' to nonzero to display the whole card instead of a one-liner.
1215 * Or, if "storename" is non-NULL, just store the person's name in that
1216 * buffer instead of displaying the card at all.
1217 * \param vcard_source the buffer containing the vcard text
1218 * \param alpha what???
1219 * \param full should we usse all lines?
1220 * \param storename where to store???
1221 * \param msgnum Citadel message pointer
1223 void display_vcard(char *vcard_source, char alpha, int full, char *storename,
1228 char this_alpha = 0;
1230 v = vcard_load(vcard_source);
1231 if (v == NULL) return;
1233 name = vcard_get_prop(v, "n", 1, 0, 0);
1235 utf8ify_rfc822_string(name);
1237 this_alpha = buf[0];
1240 if (storename != NULL) {
1241 fetchname_parsed_vcard(v, storename);
1243 else if ( (alpha == 0)
1244 || ((isalpha(alpha)) && (tolower(alpha) == tolower(this_alpha)) )
1245 || ((!isalpha(alpha)) && (!isalpha(this_alpha)))
1247 display_parsed_vcard(v, full,msgnum);
1265 * I wanna SEE that message!
1267 * msgnum Message number to display
1268 * printable_view Nonzero to display a printable view
1269 * section Optional for encapsulated message/rfc822 submessage
1271 void read_message(long msgnum, int printable_view, char *section) {
1272 struct wcsession *WCC = WC;
1275 message_summary *Msg;
1279 struct attach_link *attach_links = NULL;
1280 int num_attach_links = 0;
1281 // char mime_submessages[256] = "";
1282 char reply_references[1024] = "";
1287 char vcard_partnum[256] = "";
1288 char cal_partnum[256] = "";
1289 char *part_source = NULL;
1290 char msg4_partnum[32] = "";
1292 //// strcpy(mime_submessages, "");
1295 serv_printf("MSG4 %ld|%s", msgnum, section);
1296 StrBuf_ServGetln(Buf);
1297 if (GetServerStatus(Buf, NULL) != 1) {
1298 wprintf("<strong>");
1299 wprintf(_("ERROR:"));
1300 wprintf("</strong> %s<br />\n", &buf[4]);
1304 svputlong("MsgPrintable", printable_view);
1305 /** begin everythingamundo table */
1308 Token = NewStrBuf();
1309 Msg = (message_summary *)malloc(sizeof(message_summary));
1310 memset(Msg, 0, sizeof(message_summary));
1311 Msg->MsgBody.length=-1;
1312 while ((StrBuf_ServGetln(Buf)>=0) && !Done) {
1313 if ( (StrLength(Buf)==3) &&
1314 !strcmp(ChrPtr(Buf), "000"))
1319 wprintf(_("unexpected end of message"));
1320 wprintf(" (1)</i><br /><br />\n");
1321 wprintf("</div>\n");
1324 DestroyMessageSummary(Msg);
1332 case 0:/* Citadel Message Headers */
1333 if (StrLength(Buf) == 0) {
1337 StrBufExtract_token(Token, Buf, 0, '=');
1338 StrBufCutLeft(Buf, StrLength(Token) + 1);
1340 lprintf(1, ":: [%s] = [%s]\n", ChrPtr(Token), ChrPtr(Buf));
1341 if (GetHash(MsgHeaderHandler, SKEY(Token), &vHdr) &&
1343 Hdr = (headereval*)vHdr;
1344 Hdr->evaluator(Msg, Buf);
1345 if (Hdr->Type == 1) {
1349 else lprintf(1, "don't know how to handle message header[%s]\n", ChrPtr(Token));
1351 case 1:/* Message Mime Header */
1352 if (StrLength(Buf) == 0) {
1354 if (Msg->MsgBody.ContentType == NULL)
1355 /* end of header or no header? */
1356 Msg->MsgBody.ContentType = NewStrBufPlain(HKEY("text/plain"));
1357 /* usual end of mime header */
1361 StrBufExtract_token(Token, Buf, 0, ':');
1362 if (StrLength(Token) > 0) {
1363 StrBufCutLeft(Buf, StrLength(Token) + 1);
1364 lprintf(1, ":: [%s] = [%s]\n", ChrPtr(Token), ChrPtr(Buf));
1365 if (GetHash(MsgHeaderHandler, SKEY(Token), &vHdr) &&
1367 Hdr = (headereval*)vHdr;
1368 Hdr->evaluator(Msg, Buf);
1373 case 2: /* Message Body */
1375 if (Msg->MsgBody.length > 0) {
1376 StrBuf_ServGetBLOB(Msg->MsgBody.Data, Msg->MsgBody.length);
1378 /// todo: check next line, if not 000, append following lines
1381 if (StrLength(Msg->MsgBody.Data) > 0)
1382 StrBufAppendBufPlain(Msg->MsgBody.Data, "\n", 1, 0);
1383 StrBufAppendBuf(Msg->MsgBody.Data, Buf, 0);
1387 StrBufAppendBuf(Msg->MsgBody.Data, Buf, 0);
1393 if (GetHash(MimeRenderHandler, SKEY(Msg->MsgBody.ContentType), &vHdr) &&
1395 RenderMimeFunc Render;
1396 Render = (RenderMimeFunc)vHdr;
1397 Render(&Msg->MsgBody, NULL);
1401 if (StrLength(Msg->reply_references)> 0) {
1402 /* Trim down excessively long lists of thread references. We eliminate the
1403 * second one in the list so that the thread root remains intact.
1405 int rrtok = num_tokens(ChrPtr(Msg->reply_references), '|');
1406 int rrlen = StrLength(Msg->reply_references);
1407 if ( ((rrtok >= 3) && (rrlen > 900)) || (rrtok > 10) ) {
1408 remove_token(reply_references, 1, '|');////todo
1412 /* Generate a reply-to address */
1413 if (StrLength(Msg->Rfca) > 0) {
1414 if (Msg->reply_to == NULL)
1415 Msg->reply_to = NewStrBuf();
1416 if (StrLength(Msg->from) > 0) {
1417 StrBufPrintf(Msg->reply_to, "%s <%s>", ChrPtr(Msg->from), ChrPtr(Msg->Rfca));
1420 FlushStrBuf(Msg->reply_to);
1421 StrBufAppendBuf(Msg->reply_to, Msg->Rfca, 0);
1426 if ((StrLength(Msg->OtherNode)>0) &&
1427 (strcasecmp(ChrPtr(Msg->OtherNode), serv_info.serv_nodename)) &&
1428 (strcasecmp(ChrPtr(Msg->OtherNode), serv_info.serv_humannode)) )
1430 if (Msg->reply_to == NULL)
1431 Msg->reply_to = NewStrBuf();
1432 StrBufPrintf(Msg->reply_to,
1435 ChrPtr(Msg->OtherNode));
1438 if (Msg->reply_to == NULL)
1439 Msg->reply_to = NewStrBuf();
1440 FlushStrBuf(Msg->reply_to);
1441 StrBufAppendBuf(Msg->reply_to, Msg->from, 0);
1449 if (StrLength(Msg->cccc)> 0) {
1453 StrBuf_RFC822_to_Utf8(Msg->cccc, tmp, WCC->DefaultCharset);
1456 if (StrLength(Msg->subj)> 0) {
1460 StrBuf_RFC822_to_Utf8(Msg->subj, tmp, WCC->DefaultCharset);
1464 DoTemplate(HKEY("view_message"), NULL, Msg, CTX_MAILSUM);
1468 //// put message renderer lookup here.
1469 ///ENDBODY: /* If there are attached submessages, display them now... */
1471 /// if ( (!IsEmptyStr(mime_submessages)) && (!section[0]) ) {
1472 /// for (i=0; i<num_tokens(mime_submessages, '|'); ++i) {
1473 /// extract_token(buf, mime_submessages, i, '|', sizeof buf);
1474 /// /** use printable_view to suppress buttons */
1475 /// wprintf("<blockquote>");
1476 /// read_message(msgnum, 1, buf);
1477 /// wprintf("</blockquote>");
1482 /* Afterwards, offer links to download attachments 'n' such */
1483 if ( (num_attach_links > 0) && (!section[0]) ) {
1484 for (i=0; i<num_attach_links; ++i) {
1485 if (strcasecmp(attach_links[i].partnum, msg4_partnum)) {
1486 wprintf("%s", attach_links[i].html);
1491 /* Handler for vCard parts */
1492 if (!IsEmptyStr(vcard_partnum)) {
1493 part_source = load_mimepart(msgnum, vcard_partnum);
1494 if (part_source != NULL) {
1496 /** If it's my vCard I can edit it */
1497 if ( (!strcasecmp(WC->wc_roomname, USERCONFIGROOM))
1498 || (!strcasecmp(&WC->wc_roomname[11], USERCONFIGROOM))
1499 || (WC->wc_view == VIEW_ADDRESSBOOK)
1501 wprintf("<a href=\"edit_vcard?msgnum=%ld&partnum=%s\">",
1502 msgnum, vcard_partnum);
1503 wprintf("[%s]</a>", _("edit"));
1506 /* In all cases, display the full card */
1507 display_vcard(part_source, 0, 1, NULL,msgnum);
1511 /* Handler for calendar parts */
1512 if (!IsEmptyStr(cal_partnum)) {
1513 part_source = load_mimepart(msgnum, cal_partnum);
1514 if (part_source != NULL) {
1515 cal_process_attachment(part_source, msgnum, cal_partnum);
1524 wprintf("</div>\n");
1526 /* end everythingamundo table */
1527 if (!printable_view) {
1528 wprintf("</div>\n");
1531 if (num_attach_links > 0) {
1540 * Unadorned HTML output of an individual message, suitable
1541 * for placing in a hidden iframe, for printing, or whatever
1543 * msgnum_as_string == Message number, as a string instead of as a long int
1545 void embed_message(void) {
1548 msgnum = StrTol(WC->UrlFragment1);
1549 read_message(msgnum, 0, "");
1554 * Printable view of a message
1556 * msgnum_as_string == Message number, as a string instead of as a long int
1558 void print_message(void) {
1561 msgnum = StrTol(WC->UrlFragment1);
1562 output_headers(0, 0, 0, 0, 0, 0);
1564 hprintf("Content-type: text/html\r\n"
1566 "Connection: close\r\n",
1570 wprintf("\r\n<html>\n<head><title>");
1571 escputs(WC->wc_fullname);
1572 wprintf("</title></head>\n"
1573 "<body onLoad=\" window.print(); window.close(); \">\n"
1576 read_message(msgnum, 1, "");
1578 wprintf("\n</body></html>\n\n");
1583 * Mobile browser view of message
1585 * @param msg_num_as_string Message number as a string instead of as a long int
1587 void mobile_message_view(void) {
1589 msgnum = StrTol(WC->UrlFragment1);
1590 output_headers(1, 0, 0, 0, 0, 1);
1592 do_template("msgcontrols", NULL);
1593 read_message(msgnum,1, "");
1598 * \brief Display a message's headers
1600 * \param msgnum_as_string Message number, as a string instead of as a long int
1602 void display_headers(void) {
1606 msgnum = StrTol(WC->UrlFragment1);
1607 output_headers(0, 0, 0, 0, 0, 0);
1609 hprintf("Content-type: text/plain\r\n"
1611 "Connection: close\r\n",
1615 serv_printf("MSG2 %ld|3", msgnum);
1616 serv_getln(buf, sizeof buf);
1617 if (buf[0] == '1') {
1618 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1619 wprintf("%s\n", buf);
1629 * \brief Read message in simple, JavaScript-embeddable form for 'forward'
1630 * or 'reply quoted' operations.
1632 * NOTE: it is VITALLY IMPORTANT that we output no single-quotes or linebreaks
1633 * in this function. Doing so would throw a JavaScript error in the
1634 * 'supplied text' argument to the editor.
1636 * \param msgnum Message number of the message we want to quote
1637 * \param forward_attachments Nonzero if we want attachments to be forwarded
1639 void pullquote_message(long msgnum, int forward_attachments, int include_headers) {
1641 char mime_partnum[256];
1642 char mime_filename[256];
1643 char mime_content_type[256];
1644 char mime_charset[256];
1645 char mime_disposition[256];
1647 char *attachments = NULL;
1649 int num_attachments = 0;
1650 struct wc_attachment *att, *aptr;
1651 char m_subject[1024];
1658 int format_type = 0;
1663 iconv_t ic = (iconv_t)(-1) ;
1664 char *ibuf; /**< Buffer of characters to be converted */
1665 char *obuf; /**< Buffer for converted characters */
1666 size_t ibuflen; /**< Length of input buffer */
1667 size_t obuflen; /**< Length of output buffer */
1668 char *osav; /**< Saved pointer to output buffer */
1674 strcpy(reply_to, "");
1675 strcpy(mime_content_type, "text/plain");
1676 strcpy(mime_charset, "us-ascii");
1678 serv_printf("MSG4 %ld", msgnum);
1679 serv_getln(buf, sizeof buf);
1680 if (buf[0] != '1') {
1681 wprintf(_("ERROR:"));
1682 wprintf("%s<br />", &buf[4]);
1686 strcpy(m_subject, "");
1688 while (serv_getln(buf, sizeof buf), strcasecmp(buf, "text")) {
1689 if (!strcmp(buf, "000")) {
1690 wprintf("%s (3)", _("unexpected end of message"));
1693 if (include_headers) {
1694 if (!strncasecmp(buf, "nhdr=yes", 8))
1698 if (!strncasecmp(buf, "type=", 5))
1699 format_type = atoi(&buf[5]);
1700 if (!strncasecmp(buf, "from=", 5)) {
1701 strcpy(from, &buf[5]);
1702 wprintf(_("from "));
1703 utf8ify_rfc822_string(from);
1706 if (!strncasecmp(buf, "subj=", 5)) {
1707 strcpy(m_subject, &buf[5]);
1709 if ((!strncasecmp(buf, "hnod=", 5))
1710 && (strcasecmp(&buf[5], serv_info.serv_humannode))) {
1711 wprintf("(%s) ", &buf[5]);
1713 if ((!strncasecmp(buf, "room=", 5))
1714 && (strcasecmp(&buf[5], WC->wc_roomname))
1715 && (!IsEmptyStr(&buf[5])) ) {
1717 wprintf("%s> ", &buf[5]);
1719 if (!strncasecmp(buf, "rfca=", 5)) {
1720 strcpy(rfca, &buf[5]);
1725 if (!strncasecmp(buf, "node=", 5)) {
1726 strcpy(node, &buf[5]);
1727 if ( ((WC->room_flags & QR_NETWORK)
1728 || ((strcasecmp(&buf[5], serv_info.serv_nodename)
1729 && (strcasecmp(&buf[5], serv_info.serv_fqdn)))))
1730 && (IsEmptyStr(rfca))
1732 wprintf("@%s ", &buf[5]);
1735 if (!strncasecmp(buf, "rcpt=", 5)) {
1737 strcpy(to, &buf[5]);
1738 utf8ify_rfc822_string(to);
1741 if (!strncasecmp(buf, "time=", 5)) {
1742 webcit_fmt_date(now, atol(&buf[5]), 0);
1743 wprintf("%s ", now);
1748 * Save attachment info for later. We can't start downloading them
1749 * yet because we're in the middle of a server transaction.
1751 if (!strncasecmp(buf, "part=", 5)) {
1752 ptr = malloc( (strlen(buf) + ((attachments != NULL) ? strlen(attachments) : 0)) ) ;
1755 sprintf(ptr, "%s%s\n",
1756 ((attachments != NULL) ? attachments : ""),
1761 lprintf(9, "attachments=<%s>\n", attachments);
1767 if (include_headers) {
1770 utf8ify_rfc822_string(m_subject);
1771 if (!IsEmptyStr(m_subject)) {
1772 wprintf(_("Subject:"));
1774 msgescputs(m_subject);
1785 * Learn the content type
1787 strcpy(mime_content_type, "text/plain");
1788 while (serv_getln(buf, sizeof buf), (!IsEmptyStr(buf))) {
1789 if (!strcmp(buf, "000")) {
1790 wprintf("%s (4)", _("unexpected end of message"));
1793 if (!strncasecmp(buf, "Content-type: ", 14)) {
1795 safestrncpy(mime_content_type, &buf[14],
1796 sizeof(mime_content_type));
1797 for (i=0; i<strlen(mime_content_type); ++i) {
1798 if (!strncasecmp(&mime_content_type[i], "charset=", 8)) {
1799 safestrncpy(mime_charset, &mime_content_type[i+8],
1800 sizeof mime_charset);
1803 len = strlen(mime_content_type);
1804 for (i=0; i<len; ++i) {
1805 if (mime_content_type[i] == ';') {
1806 mime_content_type[i] = 0;
1810 len = strlen(mime_charset);
1811 for (i=0; i<len; ++i) {
1812 if (mime_charset[i] == ';') {
1813 mime_charset[i] = 0;
1820 /** Set up a character set conversion if we need to (and if we can) */
1822 if ( (strcasecmp(mime_charset, "us-ascii"))
1823 && (strcasecmp(mime_charset, "UTF-8"))
1824 && (strcasecmp(mime_charset, ""))
1826 ctdl_iconv_open("UTF-8", mime_charset, &ic);
1827 if (ic == (iconv_t)(-1) ) {
1828 lprintf(5, "%s:%d iconv_open(%s, %s) failed: %s\n",
1829 __FILE__, __LINE__, "UTF-8", mime_charset, strerror(errno));
1834 /** Messages in legacy Citadel variformat get handled thusly... */
1835 if (!strcasecmp(mime_content_type, "text/x-citadel-variformat")) {
1839 /* Boring old 80-column fixed format text gets handled this way... */
1840 else if (!strcasecmp(mime_content_type, "text/plain")) {
1841 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1844 if ((len > 0) && (buf[len-1] == '\n')) buf[--len] = 0;
1845 if ((len > 0) && (buf[len-1] == '\r')) buf[--len] = 0;
1848 if (ic != (iconv_t)(-1) ) {
1852 obuf = (char *) malloc(obuflen);
1854 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
1855 osav[SIZ-obuflen] = 0;
1856 safestrncpy(buf, osav, sizeof buf);
1862 while ((!IsEmptyStr(buf)) && (isspace(buf[len - 1])))
1865 ((!strncmp(buf, ">", 1)) || (!strncmp(buf, " >", 2)) )) {
1866 wprintf("<blockquote>");
1868 } else if ((bq == 1) &&
1869 (strncmp(buf, ">", 1)) && (strncmp(buf, " >", 2)) ) {
1870 wprintf("</blockquote>");
1874 url(buf, sizeof(buf));
1876 wprintf("</tt><br />");
1878 wprintf("</i><br />");
1881 /** HTML just gets escaped and stuffed back into the editor */
1882 else if (!strcasecmp(mime_content_type, "text/html")) {
1883 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1887 }//// TODO: charset? utf8?
1889 /** Unknown weirdness ... don't know how to handle this content type */
1891 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { }
1895 /** end of body handler */
1898 * If there were attachments, we have to download them and insert them
1899 * into the attachment chain for the forwarded message we are composing.
1901 if ( (forward_attachments) && (num_attachments) ) {
1902 for (i=0; i<num_attachments; ++i) {
1903 extract_token(buf, attachments, i, '\n', sizeof buf);
1904 extract_token(mime_filename, buf, 1, '|', sizeof mime_filename);
1905 extract_token(mime_partnum, buf, 2, '|', sizeof mime_partnum);
1906 extract_token(mime_disposition, buf, 3, '|', sizeof mime_disposition);
1907 extract_token(mime_content_type, buf, 4, '|', sizeof mime_content_type);
1908 mime_length = extract_int(buf, 5);
1911 * tracing ... uncomment if necessary
1914 lprintf(9, "fwd filename: %s\n", mime_filename);
1915 lprintf(9, "fwd partnum : %s\n", mime_partnum);
1916 lprintf(9, "fwd conttype: %s\n", mime_content_type);
1917 lprintf(9, "fwd dispose : %s\n", mime_disposition);
1918 lprintf(9, "fwd length : %d\n", mime_length);
1920 if ( (!strcasecmp(mime_disposition, "inline"))
1921 || (!strcasecmp(mime_disposition, "attachment")) ) {
1923 /* Create an attachment struct from this mime part... */
1924 att = malloc(sizeof(struct wc_attachment));
1925 memset(att, 0, sizeof(struct wc_attachment));
1926 att->length = mime_length;
1927 strcpy(att->content_type, mime_content_type);
1928 strcpy(att->filename, mime_filename);
1930 att->data = load_mimepart(msgnum, mime_partnum);
1932 /* And add it to the list. */
1933 if (WC->first_attachment == NULL) {
1934 WC->first_attachment = att;
1937 aptr = WC->first_attachment;
1938 while (aptr->next != NULL) aptr = aptr->next;
1947 if (ic != (iconv_t)(-1) ) {
1952 if (attachments != NULL) {
1960 void EvaluateMimePart(message_summary *Sum, StrBuf *Buf)
1963 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
1964 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
1965 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
1966 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
1967 mime_length = extract_int(&buf[5], 5);
1969 if ( (!strcasecmp(mime_content_type, "text/x-vcard"))
1970 || (!strcasecmp(mime_content_type, "text/vcard")) ) {
1971 strcpy(vcard_partnum, mime_partnum);
1976 message_summary *ReadOneMessageSummary(StrBuf *RawMessage, const char *DefaultSubject, long MsgNum)
1979 MsgPartEvaluatorFunc Eval;
1980 message_summary *Msg;
1989 serv_printf("MSG0 %ld|1", MsgNum); /* ask for headers only */
1991 StrBuf_ServGetln(Buf);
1992 if (GetServerStatus(Buf, NULL) == 1) {
1997 Msg = (message_summary*)malloc(sizeof(message_summary));
1998 memset(Msg, 0, sizeof(message_summary));
1999 while (len = StrBuf_ServGetln(Buf),
2001 strcmp(ChrPtr(Buf), "000")== 0)){
2003 ebuf = strchr(ChrPtr(Buf), '=');
2005 if (GetHash(MsgEvaluators, buf, nBuf, &vEval) && vEval != NULL) {
2006 Eval = (MsgPartEvaluatorFunc) vEval;
2007 StrBufCutLeft(Buf, nBuf + 1);
2010 else lprintf(1, "Don't know how to handle Message Headerline [%s]", ChrPtr(Buf));
2017 * \brief display the adressbook overview
2018 * \param msgnum the citadel message number
2019 * \param alpha what????
2021 void display_addressbook(long msgnum, char alpha) {
2023 /* char mime_partnum[SIZ]; */
2024 /* char mime_filename[SIZ]; */
2025 /* char mime_content_type[SIZ]; */
2026 ///char mime_disposition[SIZ];
2028 char vcard_partnum[SIZ];
2029 char *vcard_source = NULL;
2030 message_summary summ;////TODO: this will leak
2032 memset(&summ, 0, sizeof(summ));
2033 ///safestrncpy(summ.subj, _("(no subject)"), sizeof summ.subj);
2034 ///Load Message headers
2036 if (!IsEmptyStr(vcard_partnum)) {
2037 vcard_source = load_mimepart(msgnum, vcard_partnum);
2038 if (vcard_source != NULL) {
2040 /** Display the summary line */
2041 display_vcard(vcard_source, alpha, 0, NULL,msgnum);
2043 /** If it's my vCard I can edit it */
2044 if ( (!strcasecmp(WC->wc_roomname, USERCONFIGROOM))
2045 || (!strcasecmp(&WC->wc_roomname[11], USERCONFIGROOM))
2046 || (WC->wc_view == VIEW_ADDRESSBOOK)
2048 wprintf("<a href=\"edit_vcard?"
2049 "msgnum=%ld&partnum=%s\">",
2050 msgnum, vcard_partnum);
2051 wprintf("[%s]</a>", _("edit"));
2063 * \brief If it's an old "Firstname Lastname" style record, try to convert it.
2064 * \param namebuf name to analyze, reverse if nescessary
2066 void lastfirst_firstlast(char *namebuf) {
2067 char firstname[SIZ];
2071 if (namebuf == NULL) return;
2072 if (strchr(namebuf, ';') != NULL) return;
2074 i = num_tokens(namebuf, ' ');
2077 extract_token(lastname, namebuf, i-1, ' ', sizeof lastname);
2078 remove_token(namebuf, i-1, ' ');
2079 strcpy(firstname, namebuf);
2080 sprintf(namebuf, "%s; %s", lastname, firstname);
2084 * \brief fetch what??? name
2085 * \param msgnum the citadel message number
2086 * \param namebuf where to put the name in???
2088 void fetch_ab_name(message_summary *Msg, char *namebuf) {
2090 char mime_partnum[SIZ];
2091 char mime_filename[SIZ];
2092 char mime_content_type[SIZ];
2093 char mime_disposition[SIZ];
2095 char vcard_partnum[SIZ];
2096 char *vcard_source = NULL;
2098 message_summary summ;/// TODO this will lak
2100 if (namebuf == NULL) return;
2101 strcpy(namebuf, "");
2103 memset(&summ, 0, sizeof(summ));
2104 //////safestrncpy(summ.subj, "(no subject)", sizeof summ.subj);
2106 sprintf(buf, "MSG0 %ld|0", Msg->msgnum); /** unfortunately we need the mime info now */
2108 serv_getln(buf, sizeof buf);
2109 if (buf[0] != '1') return;
2111 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
2112 if (!strncasecmp(buf, "part=", 5)) {
2113 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
2114 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
2115 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
2116 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
2117 mime_length = extract_int(&buf[5], 5);
2119 if ( (!strcasecmp(mime_content_type, "text/x-vcard"))
2120 || (!strcasecmp(mime_content_type, "text/vcard")) ) {
2121 strcpy(vcard_partnum, mime_partnum);
2127 if (!IsEmptyStr(vcard_partnum)) {
2128 vcard_source = load_mimepart(Msg->msgnum, vcard_partnum);
2129 if (vcard_source != NULL) {
2131 /* Grab the name off the card */
2132 display_vcard(vcard_source, 0, 0, namebuf, Msg->msgnum);
2138 lastfirst_firstlast(namebuf);
2140 len = strlen(namebuf);
2141 for (i=0; i<len; ++i) {
2142 if (namebuf[i] != ';') return;
2144 strcpy(namebuf, _("(no name)"));
2150 * \brief Record compare function for sorting address book indices
2151 * \param ab1 adressbook one
2152 * \param ab2 adressbook two
2154 int abcmp(const void *ab1, const void *ab2) {
2156 (((const struct addrbookent *)ab1)->ab_name),
2157 (((const struct addrbookent *)ab2)->ab_name)
2163 * \brief Helper function for do_addrbook_view()
2164 * Converts a name into a three-letter tab label
2165 * \param tabbuf the tabbuffer to add name to
2166 * \param name the name to add to the tabbuffer
2168 void nametab(char *tabbuf, long len, char *name) {
2169 stresc(tabbuf, len, name, 0, 0);
2170 tabbuf[0] = toupper(tabbuf[0]);
2171 tabbuf[1] = tolower(tabbuf[1]);
2172 tabbuf[2] = tolower(tabbuf[2]);
2178 * \brief Render the address book using info we gathered during the scan
2179 * \param addrbook the addressbook to render
2180 * \param num_ab the number of the addressbook
2182 void do_addrbook_view(struct addrbookent *addrbook, int num_ab) {
2186 static int NAMESPERPAGE = 60;
2189 char tabfirst_label[64];
2191 char tablast_label[64];
2192 char this_tablabel[64];
2197 wprintf("<br /><br /><br /><div align=\"center\"><i>");
2198 wprintf(_("This address book is empty."));
2199 wprintf("</i></div>\n");
2204 qsort(addrbook, num_ab, sizeof(struct addrbookent), abcmp);
2207 num_pages = (num_ab / NAMESPERPAGE) + 1;
2209 tablabels = malloc(num_pages * sizeof (char *));
2210 if (tablabels == NULL) {
2211 wprintf("<br /><br /><br /><div align=\"center\"><i>");
2212 wprintf(_("An internal error has occurred."));
2213 wprintf("</i></div>\n");
2217 for (i=0; i<num_pages; ++i) {
2218 tabfirst = i * NAMESPERPAGE;
2219 tablast = tabfirst + NAMESPERPAGE - 1;
2220 if (tablast > (num_ab - 1)) tablast = (num_ab - 1);
2221 nametab(tabfirst_label, 64, addrbook[tabfirst].ab_name);
2222 nametab(tablast_label, 64, addrbook[tablast].ab_name);
2223 sprintf(this_tablabel, "%s - %s", tabfirst_label, tablast_label);
2224 tablabels[i] = strdup(this_tablabel);
2227 tabbed_dialog(num_pages, tablabels);
2230 for (i=0; i<num_ab; ++i) {
2232 if ((i / NAMESPERPAGE) != page) { /* New tab */
2233 page = (i / NAMESPERPAGE);
2235 wprintf("</tr></table>\n");
2236 end_tab(page-1, num_pages);
2238 begin_tab(page, num_pages);
2239 wprintf("<table border=0 cellspacing=0 cellpadding=3 width=100%%>\n");
2243 if ((displayed % 4) == 0) {
2244 if (displayed > 0) {
2248 wprintf("<tr bgcolor=\"#%s\">",
2249 (bg ? "DDDDDD" : "FFFFFF")
2255 wprintf("<a href=\"readfwd?startmsg=%ld?is_singlecard=1",
2256 addrbook[i].ab_msgnum);
2257 wprintf("?maxmsgs=1?is_summary=0?alpha=%s\">", bstr("alpha"));
2258 vcard_n_prettyize(addrbook[i].ab_name);
2259 escputs(addrbook[i].ab_name);
2260 wprintf("</a></td>\n");
2264 /* Placeholders for empty columns at end */
2265 if ((num_ab % 4) != 0) {
2266 for (i=0; i<(4-(num_ab % 4)); ++i) {
2267 wprintf("<td> </td>");
2271 wprintf("</tr></table>\n");
2272 end_tab((num_pages-1), num_pages);
2274 begin_tab(num_pages, num_pages);
2275 /* FIXME there ought to be something here */
2276 end_tab(num_pages, num_pages);
2278 for (i=0; i<num_pages; ++i) {
2287 * load message pointers from the server for a "read messages" operation
2289 * servcmd: the citadel command to send to the citserver
2290 * with_headers: also include some of the headers with the message numbers (more expensive)
2292 int load_msg_ptrs(char *servcmd, int with_headers)
2294 struct wcsession *WCC = WC;
2295 message_summary *Msg;
2298 ///time_t datestamp;
2299 //char fullname[128];
2300 //char nodename[128];
2301 //char inetaddr[128];
2302 //char subject[1024];
2309 ////int num_summ_alloc = 0;
2311 if (WCC->summ != NULL) {
2312 if (WCC->summ != NULL)
2313 DeleteHash(&WCC->summ);
2315 WCC->summ = NewHash(1, Flathash);
2317 maxload = 1000;/// TODO
2321 StrBuf_ServGetln(Buf);
2322 if (GetServerStatus(Buf, NULL) != 1) {
2326 // TODO if (with_headers) { //// TODO: Have Attachments?
2328 while (len = StrBuf_ServGetln(Buf),
2330 strcmp(ChrPtr(Buf), "000")!= 0))
2332 if (nummsgs < maxload) {
2333 Msg = (message_summary*)malloc(sizeof(message_summary));
2334 memset(Msg, 0, sizeof(message_summary));
2336 Msg->msgnum = StrBufExtract_long(Buf, 0, '|');
2337 Msg->date = StrBufExtract_long(Buf, 1, '|');
2339 Msg->from = NewStrBufPlain(NULL, StrLength(Buf));
2340 StrBufExtract_token(Buf2, Buf, 2, '|');
2341 if (StrLength(Buf2) != 0) {
2342 /** Handle senders with RFC2047 encoding */
2343 StrBuf_RFC822_to_Utf8(Msg->from, Buf2, WCC->DefaultCharset);
2347 StrBufExtract_token(Buf2, Buf, 3, '|');
2348 if ((StrLength(Buf2) !=0 ) &&
2349 ( ((WCC->room_flags & QR_NETWORK)
2350 || ((strcasecmp(ChrPtr(Buf2), serv_info.serv_nodename)
2351 && (strcasecmp(ChrPtr(Buf2), serv_info.serv_fqdn)))))))
2353 StrBufAppendBufPlain(Msg->from, HKEY(" @ "), 0);
2354 StrBufAppendBuf(Msg->from, Buf2, 0);
2358 StrBufExtract_token(Msg->inetaddr, Buf, 4, '|');
2361 Msg->subj = NewStrBufPlain(NULL, StrLength(Buf));
2362 StrBufExtract_token(Buf2, Buf, 5, '|');
2363 if (StrLength(Buf2) == 0)
2364 StrBufAppendBufPlain(Msg->subj, _("(no subj)"), 0, -1);
2366 StrBuf_RFC822_to_Utf8(Msg->subj, Buf2, WCC->DefaultCharset);
2367 if ((StrLength(Msg->subj) > 75) &&
2368 (StrBuf_Utf8StrLen(Msg->subj) > 75)) {
2369 StrBuf_Utf8StrCut(Msg->subj, 72);
2370 StrBufAppendBufPlain(Msg->subj, HKEY("..."), 0);
2375 if ((StrLength(Msg->from) > 25) &&
2376 (StrBuf_Utf8StrLen(Msg->from) > 25)) {
2377 StrBuf_Utf8StrCut(Msg->from, 23);
2378 StrBufAppendBufPlain(Msg->from, HKEY("..."), 0);
2380 Put(WCC->summ, (const char*)&Msg->msgnum, sizeof(Msg->msgnum), Msg, DestroyMessageSummary);
2395 * command loop for reading messages
2397 * Set oper to "readnew" or "readold" or "readfwd" or "headers"
2399 void readloop(char *oper)
2402 message_summary *Msg;
2410 long *displayed_msgs = NULL;
2411 int num_displayed = 0;
2413 int is_addressbook = 0;
2414 int is_singlecard = 0;
2415 int is_calendar = 0;
2416 struct calview calv;
2421 int lowest_displayed = (-1);
2422 int highest_displayed = 0;
2423 struct addrbookent *addrbook = NULL;
2425 const StrBuf *sortby = NULL;
2427 int SortBy = eRDate;
2428 const StrBuf *sortpref_value;
2429 int bbs_reverse = 0;
2430 struct wcsession *WCC = WC; /* This is done to make it run faster; WC is a function */
2432 const char *HashKey;
2435 if (WCC->wc_view == VIEW_WIKI) {
2436 sprintf(buf, "wiki?room=%s&page=home", WCC->wc_roomname);
2441 startmsg = lbstr("startmsg");
2442 maxmsgs = ibstr("maxmsgs");
2443 is_summary = (ibstr("is_summary") && !WCC->is_mobile);
2444 if (maxmsgs == 0) maxmsgs = DEFAULT_MAXMSGS;
2446 sortpref_value = get_room_pref("sort");
2448 sortby = sbstr("sortby");
2449 if ( (!IsEmptyStr(ChrPtr(sortby))) &&
2450 (strcasecmp(ChrPtr(sortby), ChrPtr(sortpref_value)) != 0)) {
2451 set_room_pref("sort", NewStrBufDup(sortby), 1);
2452 sortpref_value = NULL;
2453 sortpref_value = sortby;
2456 SortBy = StrToESort(sortpref_value);
2457 /* message board sort */
2458 if (SortBy == eReverse) {
2465 output_headers(1, 1, 1, 0, 0, 0);
2468 * When in summary mode, always show ALL messages instead of just
2469 * new or old. Otherwise, show what the user asked for.
2471 if (!strcmp(oper, "readnew")) {
2472 strcpy(cmd, "MSGS NEW");
2474 else if (!strcmp(oper, "readold")) {
2475 strcpy(cmd, "MSGS OLD");
2477 else if (!strcmp(oper, "do_search")) {
2478 snprintf(cmd, sizeof(cmd), "MSGS SEARCH|%s", bstr("query"));
2481 strcpy(cmd, "MSGS ALL");
2484 if ((WCC->wc_view == VIEW_MAILBOX) && (maxmsgs > 1) && !WCC->is_mobile) {
2486 if (!strcmp(oper, "do_search")) {
2487 snprintf(cmd, sizeof(cmd), "MSGS SEARCH|%s", bstr("query"));
2490 strcpy(cmd, "MSGS ALL");
2494 if ((WCC->wc_view == VIEW_ADDRESSBOOK) && (maxmsgs > 1)) {
2496 if (!strcmp(oper, "do_search")) {
2497 snprintf(cmd, sizeof(cmd), "MSGS SEARCH|%s", bstr("query"));
2500 strcpy(cmd, "MSGS ALL");
2505 if (is_summary) { /**< fetch header summary */
2506 snprintf(cmd, sizeof(cmd), "MSGS %s|%s||1",
2507 (!strcmp(oper, "do_search") ? "SEARCH" : "ALL"),
2508 (!strcmp(oper, "do_search") ? bstr("query") : "")
2513 if (WCC->is_mobile) {
2515 snprintf(cmd, sizeof(cmd), "MSGS %s|%s||1",
2516 (!strcmp(oper, "do_search") ? "SEARCH" : "ALL"),
2517 (!strcmp(oper, "do_search") ? bstr("query") : "")
2523 * Are we doing a summary view? If so, we need to know old messages
2524 * and new messages, so we can do that pretty boldface thing for the
2527 strcpy(old_msgs, "");
2528 if ((is_summary) || (WCC->wc_default_view == VIEW_CALENDAR) || WCC->is_mobile){
2530 serv_getln(buf, sizeof buf);
2531 if (buf[0] == '2') {
2532 strcpy(old_msgs, &buf[4]);
2536 is_singlecard = ibstr("is_singlecard");
2538 if (WCC->wc_default_view == VIEW_CALENDAR) { /**< calendar */
2540 strcpy(cmd, "MSGS ALL|||1");
2542 parse_calendar_view_request(&calv);
2544 if (WCC->wc_default_view == VIEW_TASKS) { /**< tasks */
2546 strcpy(cmd, "MSGS ALL");
2549 if (WCC->wc_default_view == VIEW_NOTES) { /**< notes */
2551 strcpy(cmd, "MSGS ALL");
2556 wprintf("<div id=\"new_notes_here\"></div>\n");
2559 nummsgs = load_msg_ptrs(cmd, (is_summary || WCC->is_mobile));
2562 if ((!is_tasks) && (!is_calendar) && (!is_notes) && (!is_addressbook)) {
2563 wprintf("<div align=\"center\"><br /><em>");
2564 if (!strcmp(oper, "readnew")) {
2565 wprintf(_("No new messages."));
2566 } else if (!strcmp(oper, "readold")) {
2567 wprintf(_("No old messages."));
2569 wprintf(_("No messages here."));
2571 wprintf("</em><br /></div>\n");
2577 if ((is_summary) || (WCC->wc_default_view == VIEW_CALENDAR) || WCC->is_mobile){
2579 message_summary *Msg;
2581 at = GetNewHashPos();
2582 while (GetNextHashPos(WCC->summ, at, &HKLen, &HashKey, &vMsg)) {
2583 /** Are you a new message, or an old message? */
2584 Msg = (message_summary*) vMsg;
2586 if (is_msg_in_mset(old_msgs, Msg->msgnum)) {
2597 if (startmsg == 0L) {
2599 startmsg = WCC->msgarr[(nummsgs >= maxmsgs) ? (nummsgs - maxmsgs) : 0];
2602 startmsg = WCC->msgarr[0];
2606 if (is_summary || WCC->is_mobile) {
2607 SortByPayload(WCC->summ, SortFuncs[SortBy]);
2612 wprintf("<script language=\"javascript\" type=\"text/javascript\">"
2613 " document.onkeydown = CtdlMsgListKeyPress; "
2614 " if (document.layers) { "
2615 " document.captureEvents(Event.KEYPRESS); "
2620 /** note that Date and Delete are now in the same column */
2621 wprintf("<div id=\"message_list_hdr\">"
2622 "<div class=\"fix_scrollbar_bug\">"
2623 "<table cellspacing=0 style=\"width:100%%\">"
2626 wprintf("<th width=%d%%>%s <a href=\"readfwd?startmsg=1?maxmsgs=9999999?is_summary=1?sortby=%s\"><img border=\"0\" src=\"%s\" /></a> </th>\n"
2627 "<th width=%d%%>%s <a href=\"readfwd?startmsg=1?maxmsgs=9999999?is_summary=1?sortby=%s\"><img border=\"0\" src=\"%s\" /></a> </th>\n"
2628 "<th width=%d%%>%s <a href=\"readfwd?startmsg=1?maxmsgs=9999999?is_summary=1?sortby=%s\"><img border=\"0\" src=\"%s\" /></a> \n"
2630 "<input type=\"submit\" name=\"delete_button\" id=\"delbutton\" "
2631 " onClick=\"CtdlDeleteSelectedMessages(event)\" "
2638 SortByStrings[SubjectInvertSortString[SortBy]],
2639 SortIcons[SortSubjectToIcon[SortBy]],
2640 SENDER_COL_WIDTH_PCT,
2642 SortByStrings[SenderInvertSortString[SortBy]],
2643 SortIcons[SortSenderToIcon[SortBy]],
2644 DATE_PLUS_BUTTONS_WIDTH_PCT,
2646 SortByStrings[DateInvertSortString[SortBy]],
2647 SortIcons[SortDateToIcon[SortBy]],
2650 wprintf("</table></div></div>\n");
2651 wprintf("<div id=\"message_list\">"
2653 "<div class=\"fix_scrollbar_bug\">\n"
2654 "<table class=\"mailbox_summary\" id=\"summary_headers\" "
2655 "cellspacing=0 style=\"width:100%%;-moz-user-select:none;\">"
2657 } else if (WCC->is_mobile) {
2658 wprintf("<div id=\"message_list\">");
2663 * Set the "is_bbview" variable if it appears that we are looking at
2664 * a classic bulletin board view.
2666 if ((!is_tasks) && (!is_calendar) && (!is_addressbook)
2667 && (!is_notes) && (!is_singlecard) && (!is_summary)) {
2672 * If we're not currently looking at ALL requested
2673 * messages, then display the selector bar
2676 /** begin bbview scroller */
2677 wprintf("<form name=\"msgomatictop\" class=\"selector_top\" > \n <p>");
2678 wprintf(_("Reading #"));//// TODO this isn't used, should it? : , lowest_displayed, highest_displayed);
2680 wprintf("<select name=\"whichones\" size=\"1\" "
2681 "OnChange=\"location.href=msgomatictop.whichones.options"
2682 "[selectedIndex].value\">\n");
2685 for (b=nummsgs-1; b>=0; b = b - maxmsgs) {
2687 lo = b - maxmsgs + 2;
2689 wprintf("<option %s value="
2694 "%d-%d</option> \n",
2695 ((WCC->msgarr[lo-1] == startmsg) ? "selected" : ""),
2704 for (b=0; b<nummsgs; b = b + maxmsgs) {
2706 hi = b + maxmsgs + 1;
2707 if (hi > nummsgs) hi = nummsgs;
2708 wprintf("<option %s value="
2713 "%d-%d</option> \n",
2714 ((WCC->msgarr[b] == startmsg) ? "selected" : ""),
2723 wprintf("<option value=\"%s?startmsg=%ld"
2724 "&maxmsgs=9999999&is_summary=%d\">",
2726 WCC->msgarr[0], is_summary);
2728 wprintf("</option>");
2729 wprintf("</select> ");
2730 wprintf(_("of %d messages."), nummsgs);
2732 /** forward/reverse */
2733 wprintf("<input type=\"radio\" %s name=\"direction\" value=\"\""
2734 "OnChange=\"location.href='%s?sortby=forward'\"",
2735 (bbs_reverse ? "" : "checked"),
2739 wprintf(_("oldest to newest"));
2740 wprintf(" ");
2742 wprintf("<input type=\"radio\" %s name=\"direction\" value=\"\""
2743 "OnChange=\"location.href='%s?sortby=reverse'\"",
2744 (bbs_reverse ? "checked" : ""),
2748 wprintf(_("newest to oldest"));
2751 wprintf("</p></form>\n");
2752 /** end bbview scroller */
2755 at = GetNewHashPos();
2756 while (GetNextHashPos(WCC->summ, at, &HKLen, &HashKey, &vMsg)) {
2757 Msg = (message_summary*) vMsg;
2758 if ((Msg->msgnum >= startmsg) && (num_displayed < maxmsgs)) {
2760 /** Display the message */
2762 DoTemplate(HKEY("section_mailsummary"), NULL, Msg, CTX_MAILSUM);
2764 else if (is_addressbook) {
2765 fetch_ab_name(Msg, buf);
2767 addrbook = realloc(addrbook,
2768 (sizeof(struct addrbookent) * num_ab) );
2769 safestrncpy(addrbook[num_ab-1].ab_name, buf,
2770 sizeof(addrbook[num_ab-1].ab_name));
2771 addrbook[num_ab-1].ab_msgnum = Msg->msgnum;
2773 else if (is_calendar) {
2774 load_calendar_item(Msg, Msg->is_new, &calv);
2776 else if (is_tasks) {
2777 display_task(Msg, Msg->is_new);
2779 else if (is_notes) {
2780 display_note(Msg, Msg->is_new);
2781 } else if (WCC->is_mobile) {
2782 DoTemplate(HKEY("section_mailsummary"), NULL, Msg, CTX_MAILSUM);
2785 if (displayed_msgs == NULL) {
2786 displayed_msgs = malloc(sizeof(long) *
2787 (maxmsgs<nummsgs ? maxmsgs : nummsgs));
2789 displayed_msgs[num_displayed] = Msg->msgnum;
2792 if (lowest_displayed < 0) lowest_displayed = a;
2793 highest_displayed = a;
2801 if (displayed_msgs != NULL) {
2803 qsort(displayed_msgs, num_displayed, sizeof(long), longcmp_r);
2806 /** if we do a split bbview in the future, begin messages div here */
2808 for (a=0; a<num_displayed; ++a) {
2809 read_message(displayed_msgs[a], 0, "");
2812 /** if we do a split bbview in the future, end messages div here */
2814 free(displayed_msgs);
2815 displayed_msgs = NULL;
2820 "</div>\n"); /**< end of 'fix_scrollbar_bug' div */
2821 wprintf("</div>"); /**< end of 'message_list' div */
2823 /** Here's the grab-it-to-resize-the-message-list widget */
2824 wprintf("<div id=\"resize_msglist\" "
2825 "onMouseDown=\"CtdlResizeMsgListMouseDown(event)\">"
2826 "<div class=\"fix_scrollbar_bug\"> <hr>"
2830 wprintf("<div id=\"preview_pane\">"); /**< The preview pane will initially be empty */
2831 } else if (WCC->is_mobile) {
2836 * Bump these because although we're thinking in zero base, the user
2837 * is a drooling idiot and is thinking in one base.
2840 ++highest_displayed;
2843 * If we're not currently looking at ALL requested
2844 * messages, then display the selector bar
2847 /** begin bbview scroller */
2848 wprintf("<form name=\"msgomatic\" class=\"selector_bottom\" > \n <p>");
2849 wprintf(_("Reading #")); /// TODO: this isn't used: , lowest_displayed, highest_displayed);
2851 wprintf("<select name=\"whichones\" size=\"1\" "
2852 "OnChange=\"location.href=msgomatic.whichones.options"
2853 "[selectedIndex].value\">\n");
2856 for (b=nummsgs-1; b>=0; b = b - maxmsgs) {
2858 lo = b - maxmsgs + 2;
2860 wprintf("<option %s value="
2865 "%d-%d</option> \n",
2866 ((WCC->msgarr[lo-1] == startmsg) ? "selected" : ""),
2875 for (b=0; b<nummsgs; b = b + maxmsgs) {
2877 hi = b + maxmsgs + 1;
2878 if (hi > nummsgs) hi = nummsgs;
2879 wprintf("<option %s value="
2884 "%d-%d</option> \n",
2885 ((WCC->msgarr[b] == startmsg) ? "selected" : ""),
2894 wprintf("<option value=\"%s&startmsg=%ld"
2895 "&maxmsgs=9999999&is_summary=%d\">",
2897 WCC->msgarr[0], is_summary);
2899 wprintf("</option>");
2900 wprintf("</select> ");
2901 wprintf(_("of %d messages."), nummsgs);
2903 /** forward/reverse */
2904 wprintf("<input type=\"radio\" %s name=\"direction\" value=\"\""
2905 "OnChange=\"location.href='%s&sortby=forward'\"",
2906 (bbs_reverse ? "" : "checked"),
2910 wprintf(_("oldest to newest"));
2911 wprintf(" ");
2912 wprintf("<input type=\"radio\" %s name=\"direction\" value=\"\""
2913 "OnChange=\"location.href='%s&sortby=reverse'\"",
2914 (bbs_reverse ? "checked" : ""),
2918 wprintf(_("newest to oldest"));
2921 wprintf("</p></form>\n");
2922 /** end bbview scroller */
2927 do_tasks_view(); /** Render the task list */
2931 render_calendar_view(&calv);
2934 if (is_addressbook) {
2935 do_addrbook_view(addrbook, num_ab); /** Render the address book */
2938 /** Note: wDumpContent() will output one additional </div> tag. */
2939 wprintf("</div>\n"); /** end of 'content' div */
2942 /** free the summary */
2943 if (WCC->summ != NULL) {
2944 DeleteHash(&WCC->summ);
2946 if (addrbook != NULL) free(addrbook);
2951 * Back end for post_message()
2952 * ... this is where the actual message gets transmitted to the server.
2954 void post_mime_to_server(void) {
2955 char top_boundary[SIZ];
2956 char alt_boundary[SIZ];
2957 int is_multipart = 0;
2959 struct wc_attachment *att;
2961 size_t encoded_length;
2962 size_t encoded_strlen;
2963 char *txtmail = NULL;
2965 sprintf(top_boundary, "Citadel--Multipart--%s--%04x--%04x",
2966 serv_info.serv_fqdn,
2970 sprintf(alt_boundary, "Citadel--Multipart--%s--%04x--%04x",
2971 serv_info.serv_fqdn,
2976 /* RFC2045 requires this, and some clients look for it... */
2977 serv_puts("MIME-Version: 1.0");
2978 serv_puts("X-Mailer: " PACKAGE_STRING);
2980 /* If there are attachments, we have to do multipart/mixed */
2981 if (WC->first_attachment != NULL) {
2986 /* Remember, serv_printf() appends an extra newline */
2987 serv_printf("Content-type: multipart/mixed; boundary=\"%s\"\n", top_boundary);
2988 serv_printf("This is a multipart message in MIME format.\n");
2989 serv_printf("--%s", top_boundary);
2992 /* Remember, serv_printf() appends an extra newline */
2993 serv_printf("Content-type: multipart/alternative; "
2994 "boundary=\"%s\"\n", alt_boundary);
2995 serv_printf("This is a multipart message in MIME format.\n");
2996 serv_printf("--%s", alt_boundary);
2998 serv_puts("Content-type: text/plain; charset=utf-8");
2999 serv_puts("Content-Transfer-Encoding: quoted-printable");
3001 txtmail = html_to_ascii(bstr("msgtext"), 0, 80, 0);
3002 text_to_server_qp(txtmail); /* Transmit message in quoted-printable encoding */
3005 serv_printf("--%s", alt_boundary);
3007 serv_puts("Content-type: text/html; charset=utf-8");
3008 serv_puts("Content-Transfer-Encoding: quoted-printable");
3010 serv_puts("<html><body>\r\n");
3011 text_to_server_qp(bstr("msgtext")); /* Transmit message in quoted-printable encoding */
3012 serv_puts("</body></html>\r\n");
3014 serv_printf("--%s--", alt_boundary);
3018 /* Add in the attachments */
3019 for (att = WC->first_attachment; att!=NULL; att=att->next) {
3021 encoded_length = ((att->length * 150) / 100);
3022 encoded = malloc(encoded_length);
3023 if (encoded == NULL) break;
3024 encoded_strlen = CtdlEncodeBase64(encoded, att->data, att->length, 1);
3026 serv_printf("--%s", top_boundary);
3027 serv_printf("Content-type: %s", att->content_type);
3028 serv_printf("Content-disposition: attachment; filename=\"%s\"", att->filename);
3029 serv_puts("Content-transfer-encoding: base64");
3031 serv_write(encoded, encoded_strlen);
3036 serv_printf("--%s--", top_boundary);
3044 * Post message (or don't post message)
3046 * Note regarding the "dont_post" variable:
3047 * A random value (actually, it's just a timestamp) is inserted as a hidden
3048 * field called "postseq" when the display_enter page is generated. This
3049 * value is checked when posting, using the static variable dont_post. If a
3050 * user attempts to post twice using the same dont_post value, the message is
3051 * discarded. This prevents the accidental double-saving of the same message
3052 * if the user happens to click the browser "back" button.
3054 void post_message(void)
3057 StrBuf *encoded_subject = NULL;
3058 static long dont_post = (-1L);
3059 struct wc_attachment *att, *aptr;
3060 int is_anonymous = 0;
3061 const StrBuf *display_name = NULL;
3062 struct wcsession *WCC = WC;
3064 if (havebstr("force_room")) {
3065 gotoroom(bstr("force_room"));
3068 if (havebstr("display_name")) {
3069 display_name = sbstr("display_name");
3070 if (!strcmp(ChrPtr(display_name), "__ANONYMOUS__")) {
3071 display_name = NULL;
3076 if (WCC->upload_length > 0) {
3078 lprintf(9, "%s:%d: we are uploading %d bytes\n", __FILE__, __LINE__, WCC->upload_length);
3079 /** There's an attachment. Save it to this struct... */
3080 att = malloc(sizeof(struct wc_attachment));
3081 memset(att, 0, sizeof(struct wc_attachment));
3082 att->length = WCC->upload_length;
3083 strcpy(att->content_type, WCC->upload_content_type);
3084 strcpy(att->filename, WCC->upload_filename);
3087 /** And add it to the list. */
3088 if (WCC->first_attachment == NULL) {
3089 WCC->first_attachment = att;
3092 aptr = WCC->first_attachment;
3093 while (aptr->next != NULL) aptr = aptr->next;
3098 * Mozilla sends a simple filename, which is what we want,
3099 * but Satan's Browser sends an entire pathname. Reduce
3100 * the path to just a filename if we need to.
3102 while (num_tokens(att->filename, '/') > 1) {
3103 remove_token(att->filename, 0, '/');
3105 while (num_tokens(att->filename, '\\') > 1) {
3106 remove_token(att->filename, 0, '\\');
3110 * Transfer control of this memory from the upload struct
3111 * to the attachment struct.
3113 att->data = WCC->upload;
3114 WCC->upload_length = 0;
3120 if (havebstr("cancel_button")) {
3121 sprintf(WCC->ImportantMessage,
3122 _("Cancelled. Message was not posted."));
3123 } else if (havebstr("attach_button")) {
3126 } else if (lbstr("postseq") == dont_post) {
3127 sprintf(WCC->ImportantMessage,
3128 _("Automatically cancelled because you have already "
3129 "saved this message."));
3131 const char CMD[] = "ENT0 1|%s|%d|4|%s|%s||%s|%s|%s|%s|%s";
3132 const StrBuf *Recp = NULL;
3133 const StrBuf *Cc = NULL;
3134 const StrBuf *Bcc = NULL;
3135 const StrBuf *Wikipage = NULL;
3136 const StrBuf *my_email_addr = NULL;
3137 StrBuf *CmdBuf = NULL;;
3138 StrBuf *references = NULL;
3140 if (havebstr("references"))
3142 const StrBuf *ref = sbstr("references");
3143 references = NewStrBufPlain(ChrPtr(ref), StrLength(ref));
3144 lprintf(9, "Converting: %s\n", ChrPtr(references));
3145 StrBufReplaceChars(references, '|', '!');
3146 lprintf(9, "Converted: %s\n", ChrPtr(references));
3148 if (havebstr("subject")) {
3151 * make enough room for the encoded string;
3152 * plus the QP header
3154 Subj = sbstr("subject");
3156 StrBufRFC2047encode(&encoded_subject, Subj);
3158 Recp = sbstr("recp");
3161 Wikipage = sbstr("wikipage");
3162 my_email_addr = sbstr("my_email_addr");
3164 CmdBuf = NewStrBufPlain(NULL,
3167 StrLength(encoded_subject) +
3170 StrLength(Wikipage) +
3171 StrLength(my_email_addr) +
3172 StrLength(references));
3174 StrBufPrintf(CmdBuf,
3178 ChrPtr(encoded_subject),
3179 ChrPtr(display_name),
3183 ChrPtr(my_email_addr),
3184 ChrPtr(references));
3185 FreeStrBuf(&references);
3187 lprintf(9, "%s\n", CmdBuf);
3188 serv_puts(ChrPtr(CmdBuf));
3189 serv_getln(buf, sizeof buf);
3190 FreeStrBuf(&CmdBuf);
3191 FreeStrBuf(&encoded_subject);
3192 if (buf[0] == '4') {
3193 post_mime_to_server();
3194 if ( (havebstr("recp"))
3195 || (havebstr("cc" ))
3196 || (havebstr("bcc" ))
3198 sprintf(WCC->ImportantMessage, _("Message has been sent.\n"));
3201 sprintf(WC->ImportantMessage, _("Message has been posted.\n"));
3203 dont_post = lbstr("postseq");
3205 lprintf(9, "%s:%d: server post error: %s\n", __FILE__, __LINE__, buf);
3206 sprintf(WC->ImportantMessage, "%s", &buf[4]);
3212 free_attachments(WCC);
3215 * We may have been supplied with instructions regarding the location
3216 * to which we must return after posting. If found, go there.
3218 if (havebstr("return_to")) {
3219 http_redirect(bstr("return_to"));
3222 * If we were editing a page in a wiki room, go to that page now.
3224 else if (havebstr("wikipage")) {
3225 snprintf(buf, sizeof buf, "wiki?page=%s", bstr("wikipage"));
3229 * Otherwise, just go to the "read messages" loop.
3232 readloop("readnew");
3240 * \brief display the message entry screen
3242 void display_enter(void)
3247 const StrBuf *display_name = NULL;
3248 struct wc_attachment *att;
3249 int recipient_required = 0;
3250 int subject_required = 0;
3251 int recipient_bad = 0;
3252 int is_anonymous = 0;
3253 long existing_page = (-1L);
3254 struct wcsession *WCC = WC;
3258 if (havebstr("force_room")) {
3259 gotoroom(bstr("force_room"));
3262 display_name = sbstr("display_name");
3263 if (!strcmp(ChrPtr(display_name), "__ANONYMOUS__")) {
3264 display_name = NULL;
3268 /** First test to see whether this is a room that requires recipients to be entered */
3269 serv_puts("ENT0 0");
3270 serv_getln(buf, sizeof buf);
3272 if (!strncmp(buf, "570", 3)) { /** 570 means that we need a recipient here */
3273 recipient_required = 1;
3275 else if (buf[0] != '2') { /** Any other error means that we cannot continue */
3276 sprintf(WCC->ImportantMessage, "%s", &buf[4]);
3277 readloop("readnew");
3281 /* Is the server strongly recommending that the user enter a message subject? */
3282 if ((buf[3] != '\0') && (buf[4] != '\0')) {
3283 subject_required = extract_int(&buf[4], 1);
3287 * Are we perhaps in an address book view? If so, then an "enter
3288 * message" command really means "add new entry."
3290 if (WCC->wc_default_view == VIEW_ADDRESSBOOK) {
3291 do_edit_vcard(-1, "", "", WCC->wc_roomname);
3296 * Are we perhaps in a calendar room? If so, then an "enter
3297 * message" command really means "add new calendar item."
3299 if (WCC->wc_default_view == VIEW_CALENDAR) {
3300 display_edit_event();
3305 * Are we perhaps in a tasks view? If so, then an "enter
3306 * message" command really means "add new task."
3308 if (WCC->wc_default_view == VIEW_TASKS) {
3309 display_edit_task();
3314 * Otherwise proceed normally.
3315 * Do a custom room banner with no navbar...
3317 output_headers(1, 1, 2, 0, 0, 0);
3318 wprintf("<div id=\"banner\">\n");
3319 embed_room_banner(NULL, navbar_none);
3320 wprintf("</div>\n");
3321 wprintf("<div id=\"content\">\n"
3322 "<div class=\"fix_scrollbar_bug message \">");
3324 /* Now check our actual recipients if there are any */
3325 if (recipient_required) {
3326 const StrBuf *Recp = NULL;
3327 const StrBuf *Cc = NULL;
3328 const StrBuf *Bcc = NULL;
3329 const StrBuf *Wikipage = NULL;
3330 StrBuf *CmdBuf = NULL;;
3331 const char CMD[] = "ENT0 0|%s|%d|0||%s||%s|%s|%s";
3333 Recp = sbstr("recp");
3336 Wikipage = sbstr("wikipage");
3338 CmdBuf = NewStrBufPlain(NULL,
3341 StrLength(display_name) +
3344 StrLength(Wikipage));
3346 StrBufPrintf(CmdBuf,
3350 ChrPtr(display_name),
3354 serv_puts(ChrPtr(CmdBuf));
3355 serv_getln(buf, sizeof buf);
3356 FreeStrBuf(&CmdBuf);
3358 if (!strncmp(buf, "570", 3)) { /** 570 means we have an invalid recipient listed */
3359 if (havebstr("recp") &&
3365 else if (buf[0] != '2') { /** Any other error means that we cannot continue */
3366 wprintf("<em>%s</em><br />\n", &buf[4]);
3371 /** If we got this far, we can display the message entry screen. */
3373 /* begin message entry screen */
3375 "enctype=\"multipart/form-data\" "
3377 "accept-charset=\"UTF-8\" "
3379 "name=\"enterform\""
3381 wprintf("<input type=\"hidden\" name=\"postseq\" value=\"%ld\">\n", now);
3382 if (WCC->wc_view == VIEW_WIKI) {
3383 wprintf("<input type=\"hidden\" name=\"wikipage\" value=\"%s\">\n", bstr("wikipage"));
3385 wprintf("<input type=\"hidden\" name=\"return_to\" value=\"%s\">\n", bstr("return_to"));
3386 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WCC->nonce);
3387 wprintf("<input type=\"hidden\" name=\"force_room\" value=\"");
3388 escputs(WCC->wc_roomname);
3390 wprintf("<input type=\"hidden\" name=\"references\" value=\"");
3391 escputs(bstr("references"));
3394 /** submit or cancel buttons */
3395 wprintf("<p class=\"send_edit_msg\">");
3396 wprintf("<input type=\"submit\" name=\"send_button\" value=\"");
3397 if (recipient_required) {
3398 wprintf(_("Send message"));
3400 wprintf(_("Post message"));
3403 "<input type=\"submit\" name=\"cancel_button\" value=\"%s\">\n", _("Cancel"));
3408 wprintf("<img src=\"static/newmess3_24x.gif\" class=\"imgedit\">");
3409 wprintf(" "); /** header bar */
3410 webcit_fmt_date(buf, now, 0);
3412 wprintf("\n"); /** header bar */
3414 wprintf("<table width=\"100%%\" class=\"edit_msg_table\">");
3416 wprintf("<th><label for=\"from_id\" > ");
3417 wprintf(_(" <I>from</I> "));
3418 wprintf("</label></th>");
3420 wprintf("<td colspan=\"2\">");
3422 /* Allow the user to select any of his valid screen names */
3424 wprintf("<select name=\"display_name\" size=1 id=\"from_id\">\n");
3427 serv_getln(buf, sizeof buf);
3428 if (buf[0] == '1') {
3429 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
3430 wprintf("<option %s value=\"",
3431 ((!strcasecmp(bstr("display_name"), buf)) ? "selected" : "")
3436 wprintf("</option>\n");
3440 if (WCC->room_flags & QR_ANONOPT) {
3441 wprintf("<option %s value=\"__ANONYMOUS__\">%s</option>\n",
3442 ((!strcasecmp(bstr("__ANONYMOUS__"), WCC->wc_fullname)) ? "selected" : ""),
3447 wprintf("</select>\n");
3449 /* If this is an email (not a post), allow the user to select any of his
3450 * valid email addresses.
3452 if (recipient_required) {
3454 serv_getln(buf, sizeof buf);
3455 if (buf[0] == '1') {
3456 wprintf("<select name=\"my_email_addr\" size=1>\n");
3457 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
3458 wprintf("<option value=\"");
3462 wprintf("></option>\n");
3464 wprintf("</select>\n");
3468 wprintf(_(" <I>in</I> "));
3469 escputs(WCC->wc_roomname);
3471 wprintf("</td></tr>");
3473 if (recipient_required) {
3477 wprintf("<tr><th><label for=\"recp_id\"> ");
3479 wprintf("</label></th>"
3480 "<td><input autocomplete=\"off\" type=\"text\" name=\"recp\" id=\"recp_id\" value=\"");
3481 ccraw = xbstr("recp", &len);
3482 copy = (char*) malloc(len * 2 + 1);
3483 memcpy(copy, ccraw, len + 1);
3484 utf8ify_rfc822_string(copy);
3487 wprintf("\" size=45 maxlength=1000 />");
3488 wprintf("<div class=\"auto_complete\" id=\"recp_name_choices\"></div>");
3489 wprintf("</td><td rowspan=\"3\" align=\"left\" valign=\"top\">");
3491 /** Pop open an address book -- begin **/
3493 "<a href=\"javascript:PopOpenAddressBook('recp_id|%s|cc_id|%s|bcc_id|%s');\" "
3495 "<img align=middle border=0 width=24 height=24 src=\"static/viewcontacts_24x.gif\">"
3497 _("To:"), _("CC:"), _("BCC:"),
3498 _("Contacts"), _("Contacts")
3500 /** Pop open an address book -- end **/
3502 wprintf("</td></tr>");
3504 wprintf("<tr><th><label for=\"cc_id\"> ");
3506 wprintf("</label></th>"
3507 "<td><input autocomplete=\"off\" type=\"text\" name=\"cc\" id=\"cc_id\" value=\"");
3508 ccraw = xbstr("cc", &len);
3509 copy = (char*) malloc(len * 2 + 1);
3510 memcpy(copy, ccraw, len + 1);
3511 utf8ify_rfc822_string(copy);
3514 wprintf("\" size=45 maxlength=1000 />");
3515 wprintf("<div class=\"auto_complete\" id=\"cc_name_choices\"></div>");
3516 wprintf("</td></tr>");
3518 wprintf("<tr><th><label for=\"bcc_id\"> ");
3520 wprintf("</label></th>"
3521 "<td><input autocomplete=\"off\" type=\"text\" name=\"bcc\" id=\"bcc_id\" value=\"");
3522 ccraw = xbstr("bcc", &len);
3523 copy = (char*) malloc(len * 2 + 1);
3524 memcpy(copy, ccraw, len + 1);
3525 utf8ify_rfc822_string(copy);
3528 wprintf("\" size=45 maxlength=1000 />");
3529 wprintf("<div class=\"auto_complete\" id=\"bcc_name_choices\"></div>");
3530 wprintf("</td></tr>");
3532 /** Initialize the autocomplete ajax helpers (found in wclib.js) */
3533 wprintf("<script type=\"text/javascript\"> \n"
3534 " activate_entmsg_autocompleters(); \n"
3540 wprintf("<tr><th><label for=\"subject_id\" > ");
3541 if (recipient_required || subject_required) {
3542 wprintf(_("Subject:"));
3545 wprintf(_("Subject (optional):"));
3547 wprintf("</label></th>"
3548 "<td colspan=\"2\">"
3549 "<input type=\"text\" name=\"subject\" id=\"subject_id\" value=\"");
3550 escputs(bstr("subject"));
3551 wprintf("\" size=45 maxlength=70>\n");
3552 wprintf("</td></tr>");
3554 wprintf("<tr><td colspan=\"3\">\n");
3556 wprintf("<textarea name=\"msgtext\" cols=\"80\" rows=\"15\">");
3558 /** If we're continuing from a previous edit, put our partially-composed message back... */
3559 msgescputs(bstr("msgtext"));
3561 /* If we're forwarding a message, insert it here... */
3562 if (lbstr("fwdquote") > 0L) {
3563 wprintf("<br><div align=center><i>");
3564 wprintf(_("--- forwarded message ---"));
3565 wprintf("</i></div><br>");
3566 pullquote_message(lbstr("fwdquote"), 1, 1);
3569 /** If we're replying quoted, insert the quote here... */
3570 else if (lbstr("replyquote") > 0L) {
3573 pullquote_message(lbstr("replyquote"), 0, 1);
3574 wprintf("</blockquote><br>");
3577 /** If we're editing a wiki page, insert the existing page here... */
3578 else if (WCC->wc_view == VIEW_WIKI) {
3579 safestrncpy(buf, bstr("wikipage"), sizeof buf);
3580 str_wiki_index(buf);
3581 existing_page = locate_message_by_uid(buf);
3582 if (existing_page >= 0L) {
3583 pullquote_message(existing_page, 1, 0);
3587 /** Insert our signature if appropriate... */
3588 if ( (WCC->is_mailbox) && !yesbstr("sig_inserted") ) {
3590 get_pref_yesno("use_sig", &UseSig, 0);
3593 const char *sig, *esig;
3595 get_preference("signature", &ebuf);
3597 StrBufEUid_unescapize(Sig, ebuf);
3599 esig = sig + StrLength(Sig);
3600 wprintf("<br>--<br>");
3601 while (sig <= esig) {
3605 else if (*sig == '<') {
3608 else if (*sig == '>') {
3611 else if (*sig == '&') {
3614 else if (*sig == '\"') {
3617 else if (*sig == '\'') {
3620 else /* since we're utf 8, is this a good idea? if (isprint(*sig))*/ {
3621 wprintf("%c", *sig);
3629 wprintf("</textarea>\n");
3631 /** Make sure we only insert our signature once */
3632 /** We don't care if it was there or not before, it needs to be there now. */
3633 wprintf("<input type=\"hidden\" name=\"sig_inserted\" value=\"yes\">\n");
3636 * The following template embeds the TinyMCE richedit control, and automatically
3637 * transforms the textarea into a richedit textarea.
3639 do_template("richedit", NULL);
3641 /** Enumerate any attachments which are already in place... */
3642 wprintf("<div class=\"attachment buttons\"><img src=\"static/diskette_24x.gif\" class=\"imgedit\" > ");
3643 wprintf(_("Attachments:"));
3645 wprintf("<select name=\"which_attachment\" size=1>");
3646 for (att = WCC->first_attachment; att != NULL; att = att->next) {
3647 wprintf("<option value=\"");
3648 urlescputs(att->filename);
3650 escputs(att->filename);
3651 /* wprintf(" (%s, %d bytes)",att->content_type,att->length); */
3652 wprintf("</option>\n");
3654 wprintf("</select>");
3656 /** Now offer the ability to attach additional files... */
3657 wprintf(" ");
3658 wprintf(_("Attach file:"));
3659 wprintf(" <input name=\"attachfile\" class=\"attachfile\" "
3660 "size=16 type=\"file\">\n "
3661 "<input type=\"submit\" name=\"attach_button\" value=\"%s\">\n", _("Add"));
3662 wprintf("</div>"); /* End of "attachment buttons" div */
3665 wprintf("</td></tr></table>");
3667 wprintf("</form>\n");
3668 wprintf("</div>\n"); /* end of "fix_scrollbar_bug" div */
3670 /* NOTE: address_book_popup() will close the "content" div. Don't close it here. */
3671 DONE: address_book_popup();
3677 * \brief delete a message
3679 void delete_msg(void)
3684 msgid = lbstr("msgid");
3686 if (WC->wc_is_trash) { /** Delete from Trash is a real delete */
3687 serv_printf("DELE %ld", msgid);
3689 else { /** Otherwise move it to Trash */
3690 serv_printf("MOVE %ld|_TRASH_|0", msgid);
3693 serv_getln(buf, sizeof buf);
3694 sprintf(WC->ImportantMessage, "%s", &buf[4]);
3696 readloop("readnew");
3701 * \brief move a message to another folder
3708 msgid = lbstr("msgid");
3710 if (havebstr("move_button")) {
3711 sprintf(buf, "MOVE %ld|%s", msgid, bstr("target_room"));
3713 serv_getln(buf, sizeof buf);
3714 sprintf(WC->ImportantMessage, "%s", &buf[4]);
3716 sprintf(WC->ImportantMessage, (_("The message was not moved.")));
3719 readloop("readnew");
3727 * Confirm move of a message
3729 void confirm_move_msg(void)
3735 msgid = lbstr("msgid");
3738 output_headers(1, 1, 2, 0, 0, 0);
3739 wprintf("<div id=\"banner\">\n");
3741 wprintf(_("Confirm move of message"));
3743 wprintf("</div>\n");
3745 wprintf("<div id=\"content\" class=\"service\">\n");
3747 wprintf("<CENTER>");
3749 wprintf(_("Move this message to:"));
3750 wprintf("<br />\n");
3752 wprintf("<form METHOD=\"POST\" action=\"move_msg\">\n");
3753 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
3754 wprintf("<INPUT TYPE=\"hidden\" NAME=\"msgid\" VALUE=\"%s\">\n", bstr("msgid"));
3756 wprintf("<SELECT NAME=\"target_room\" SIZE=5>\n");
3758 serv_getln(buf, sizeof buf);
3759 if (buf[0] == '1') {
3760 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
3761 extract_token(targ, buf, 0, '|', sizeof targ);
3762 wprintf("<OPTION>");
3767 wprintf("</SELECT>\n");
3768 wprintf("<br />\n");
3770 wprintf("<INPUT TYPE=\"submit\" NAME=\"move_button\" VALUE=\"%s\">", _("Move"));
3772 wprintf("<INPUT TYPE=\"submit\" NAME=\"cancel_button\" VALUE=\"%s\">", _("Cancel"));
3773 wprintf("</form></CENTER>\n");
3775 wprintf("</CENTER>\n");
3779 void readnew(void) { readloop("readnew");}
3780 void readold(void) { readloop("readold");}
3781 void readfwd(void) { readloop("readfwd");}
3782 void headers(void) { readloop("headers");}
3783 void do_search(void) { readloop("do_search");}
3794 WebcitAddUrlHandler(HKEY("readnew"), readnew, 0);
3795 WebcitAddUrlHandler(HKEY("readold"), readold, 0);
3796 WebcitAddUrlHandler(HKEY("readfwd"), readfwd, 0);
3797 WebcitAddUrlHandler(HKEY("headers"), headers, 0);
3798 WebcitAddUrlHandler(HKEY("do_search"), do_search, 0);
3799 WebcitAddUrlHandler(HKEY("display_enter"), display_enter, 0);
3800 WebcitAddUrlHandler(HKEY("post"), post_message, 0);
3801 WebcitAddUrlHandler(HKEY("move_msg"), move_msg, 0);
3802 WebcitAddUrlHandler(HKEY("delete_msg"), delete_msg, 0);
3803 WebcitAddUrlHandler(HKEY("confirm_move_msg"), confirm_move_msg, 0);
3804 WebcitAddUrlHandler(HKEY("msg"), embed_message, NEED_URL|AJAX);
3805 WebcitAddUrlHandler(HKEY("printmsg"), print_message, NEED_URL);
3806 WebcitAddUrlHandler(HKEY("mobilemsg"), mobile_message_view, NEED_URL);
3807 WebcitAddUrlHandler(HKEY("msgheaders"), display_headers, NEED_URL);
3809 RegisterNamespace("MAIL:SUMM:DATESTR", 0, 0, tmplput_MAIL_SUMM_DATE_STR, CTX_MAILSUM);
3810 RegisterNamespace("MAIL:SUMM:DATENO", 0, 0, tmplput_MAIL_SUMM_DATE_NO, CTX_MAILSUM);
3811 RegisterNamespace("MAIL:SUMM:N", 0, 0, tmplput_MAIL_SUMM_N, CTX_MAILSUM);
3812 RegisterNamespace("MAIL:SUMM:FROM", 0, 2, tmplput_MAIL_SUMM_FROM, CTX_MAILSUM);
3813 RegisterNamespace("MAIL:SUMM:TO", 0, 2, tmplput_MAIL_SUMM_TO, CTX_MAILSUM);
3814 RegisterNamespace("MAIL:SUMM:SUBJECT", 0, 4, tmplput_MAIL_SUMM_SUBJECT, CTX_MAILSUM);
3815 RegisterNamespace("MAIL:SUMM:NATTACH", 0, 0, tmplput_MAIL_SUMM_NATTACH, CTX_MAILSUM);
3816 RegisterNamespace("MAIL:SUMM:CCCC", 0, 2, tmplput_MAIL_SUMM_CCCC, CTX_MAILSUM);
3817 RegisterNamespace("MAIL:SUMM:H_NODE", 0, 2, tmplput_MAIL_SUMM_H_NODE, CTX_MAILSUM);
3818 RegisterNamespace("MAIL:SUMM:ALLRCPT", 0, 2, tmplput_MAIL_SUMM_ALLRCPT, CTX_MAILSUM);
3819 RegisterNamespace("MAIL:SUMM:ORGROOM", 0, 2, tmplput_MAIL_SUMM_ORGROOM, CTX_MAILSUM);
3820 RegisterNamespace("MAIL:SUMM:RFCA", 0, 2, tmplput_MAIL_SUMM_RFCA, CTX_MAILSUM);
3821 RegisterNamespace("MAIL:SUMM:OTHERNODE", 2, 0, tmplput_MAIL_SUMM_OTHERNODE, CTX_MAILSUM);
3822 RegisterNamespace("MAIL:SUMM:REFIDS", 0, 0, tmplput_MAIL_SUMM_REFIDS, CTX_MAILSUM);
3823 RegisterNamespace("MAIL:SUMM:INREPLYTO", 0, 2, tmplput_MAIL_SUMM_INREPLYTO, CTX_MAILSUM);
3824 RegisterNamespace("MAIL:BODY", 0, 2, tmplput_MAIL_BODY, CTX_MAILSUM);
3828 RegisterMimeRenderer(HKEY("text/x-citadel-variformat"), render_MAIL_variformat);
3829 RegisterMimeRenderer(HKEY("text/plain"), render_MAIL_text_plain);
3830 RegisterMimeRenderer(HKEY("text"), render_MAIL_text_plain);
3831 RegisterMimeRenderer(HKEY("text/html"), render_MAIL_html);
3832 RegisterMimeRenderer(HKEY(""), render_MAIL_UNKNOWN);
3835 RegisterConditional(HKEY("COND:MAIL:SUMM:UNREAD"), 0, Conditional_MAIL_SUMM_UNREAD, CTX_MAILSUM);
3836 RegisterConditional(HKEY("COND:MAIL:SUMM:H_NODE"), 0, Conditional_MAIL_SUMM_H_NODE, CTX_MAILSUM);
3837 RegisterConditional(HKEY("COND:MAIL:SUMM:OTHERNODE"), 0, Conditional_MAIL_SUMM_OTHERNODE, CTX_MAILSUM);
3839 RegisterMsgHdr(HKEY("nhdr"), examine_nhdr, 0);
3840 RegisterMsgHdr(HKEY("type"), examine_type, 0);
3841 RegisterMsgHdr(HKEY("from"), examine_from, 0);
3842 RegisterMsgHdr(HKEY("subj"), examine_subj, 0);
3843 RegisterMsgHdr(HKEY("msgn"), examine_msgn, 0);
3844 RegisterMsgHdr(HKEY("wefw"), examine_wefw, 0);
3845 RegisterMsgHdr(HKEY("cccc"), examine_cccc, 0);
3846 RegisterMsgHdr(HKEY("hnod"), examine_hnod, 0);
3847 RegisterMsgHdr(HKEY("room"), examine_room, 0);
3848 RegisterMsgHdr(HKEY("rfca"), examine_rfca, 0);
3849 RegisterMsgHdr(HKEY("node"), examine_node, 0);
3850 RegisterMsgHdr(HKEY("rcpt"), examine_rcpt, 0);
3851 RegisterMsgHdr(HKEY("time"), examine_time, 0);
3852 RegisterMsgHdr(HKEY("part"), examine_mime_part, 0);
3853 RegisterMsgHdr(HKEY("text"), examine_text, 1);
3854 RegisterMsgHdr(HKEY("X-Citadel-MSG4-Partnum"), examine_msg4_partnum, 0);
3855 RegisterMsgHdr(HKEY("Content-type"), examine_content_type, 0);
3856 RegisterMsgHdr(HKEY("Content-length"), examine_content_lengh, 0);
3857 RegisterMsgHdr(HKEY("Content-transfer-encoding"), examine_content_encoding, 0);