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
244 void DestroyMimeParts(wc_mime_attachment *Mime)
246 FreeStrBuf(&Mime->Name);
247 FreeStrBuf(&Mime->FileName);
248 FreeStrBuf(&Mime->PartNum);
249 FreeStrBuf(&Mime->Disposition);
250 FreeStrBuf(&Mime->ContentType);
251 FreeStrBuf(&Mime->Charset);
252 FreeStrBuf(&Mime->Data);
255 void DestroyMime(void *vMime)
257 wc_mime_attachment *Mime = (wc_mime_attachment*)vMime;
258 DestroyMimeParts(Mime);
262 void DestroyMessageSummary(void *vMsg)
264 message_summary *Msg = (message_summary*) vMsg;
266 FreeStrBuf(&Msg->from);
267 FreeStrBuf(&Msg->to);
268 FreeStrBuf(&Msg->subj);
269 FreeStrBuf(&Msg->reply_inreplyto);
270 FreeStrBuf(&Msg->reply_references);
271 FreeStrBuf(&Msg->cccc);
272 FreeStrBuf(&Msg->hnod);
273 FreeStrBuf(&Msg->AllRcpt);
274 FreeStrBuf(&Msg->Room);
275 FreeStrBuf(&Msg->Rfca);
276 FreeStrBuf(&Msg->OtherNode);
278 FreeStrBuf(&Msg->reply_to);
280 DeleteHash(&Msg->Attachments); /**< list of Accachments */
281 DeleteHash(&Msg->Submessages);
282 DeleteHash(&Msg->AttachLinks);
283 DeleteHash(&Msg->AllAttach);
285 DestroyMimeParts(&Msg->MsgBody);
292 void RegisterMsgHdr(const char *HeaderName, long HdrNLen, ExamineMsgHeaderFunc evaluator, int type)
295 ev = (headereval*) malloc(sizeof(headereval));
296 ev->evaluator = evaluator;
298 Put(MsgHeaderHandler, HeaderName, HdrNLen, ev, NULL);
301 void RegisterMimeRenderer(const char *HeaderName, long HdrNLen, RenderMimeFunc MimeRenderer)
303 Put(MimeRenderHandler, HeaderName, HdrNLen, MimeRenderer, reference_free_handler);
307 /*----------------------------------------------------------------------------*/
310 void examine_nhdr(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
313 if (!strncasecmp(ChrPtr(HdrLine), "yes", 8))
317 void examine_type(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
319 Msg->format_type = StrToi(HdrLine);
323 void examine_from(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
325 FreeStrBuf(&Msg->from);
326 Msg->from = NewStrBufPlain(NULL, StrLength(HdrLine));
327 StrBuf_RFC822_to_Utf8(Msg->from, HdrLine, WC->DefaultCharset, FoundCharset);
329 void tmplput_MAIL_SUMM_FROM(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
331 message_summary *Msg = (message_summary*) Context;
332 StrBufAppendBuf(Target, Msg->from, 0);
333 lprintf(1,"%s", ChrPtr(Msg->from));
338 void examine_subj(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
340 FreeStrBuf(&Msg->subj);
341 Msg->subj = NewStrBufPlain(NULL, StrLength(HdrLine));
342 StrBuf_RFC822_to_Utf8(Msg->subj, HdrLine, WC->DefaultCharset, FoundCharset);
343 lprintf(1,"%s", ChrPtr(Msg->subj));
345 void tmplput_MAIL_SUMM_SUBJECT(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
346 {/////TODO: Fwd: and RE: filter!!
347 message_summary *Msg = (message_summary*) Context;
348 StrBufAppendBuf(Target, Msg->subj, 0);
352 void examine_msgn(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
354 FreeStrBuf(&Msg->reply_inreplyto);
355 Msg->reply_inreplyto = NewStrBufPlain(NULL, StrLength(HdrLine));
356 StrBuf_RFC822_to_Utf8(Msg->reply_inreplyto, HdrLine, WC->DefaultCharset, FoundCharset);
358 void tmplput_MAIL_SUMM_INREPLYTO(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
360 message_summary *Msg = (message_summary*) Context;
361 StrBufAppendBuf(Target, Msg->reply_inreplyto, 0);
365 void examine_wefw(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
367 FreeStrBuf(&Msg->reply_references);
368 Msg->reply_references = NewStrBufPlain(NULL, StrLength(HdrLine));
369 StrBuf_RFC822_to_Utf8(Msg->reply_references, HdrLine, WC->DefaultCharset, FoundCharset);
371 void tmplput_MAIL_SUMM_REFIDS(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
373 message_summary *Msg = (message_summary*) Context;
374 StrBufAppendBuf(Target, Msg->reply_references, 0);
378 void examine_cccc(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
380 FreeStrBuf(&Msg->cccc);
381 Msg->cccc = NewStrBufPlain(NULL, StrLength(HdrLine));
382 StrBuf_RFC822_to_Utf8(Msg->cccc, HdrLine, WC->DefaultCharset, FoundCharset);
383 if (Msg->AllRcpt == NULL)
384 Msg->AllRcpt = NewStrBufPlain(NULL, StrLength(HdrLine));
385 if (StrLength(Msg->AllRcpt) > 0) {
386 StrBufAppendBufPlain(Msg->AllRcpt, HKEY(", "), 0);
388 StrBufAppendBuf(Msg->AllRcpt, Msg->cccc, 0);
390 void tmplput_MAIL_SUMM_CCCC(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
392 message_summary *Msg = (message_summary*) Context;
393 StrBufAppendBuf(Target, Msg->cccc, 0);
399 void examine_room(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
401 if ((StrLength(HdrLine) > 0) &&
402 (strcasecmp(ChrPtr(HdrLine), WC->wc_roomname))) {
403 FreeStrBuf(&Msg->Room);
404 Msg->Room = NewStrBufDup(HdrLine);
407 void tmplput_MAIL_SUMM_ORGROOM(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
409 message_summary *Msg = (message_summary*) Context;
410 StrBufAppendBuf(Target, Msg->Room, 0);
414 void examine_rfca(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
416 FreeStrBuf(&Msg->Rfca);
417 Msg->Rfca = NewStrBufDup(HdrLine);
419 void tmplput_MAIL_SUMM_RFCA(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
421 message_summary *Msg = (message_summary*) Context;
422 StrBufAppendBuf(Target, Msg->Rfca, 0);
426 void examine_node(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
428 if ( (StrLength(HdrLine) > 0) &&
429 ((WC->room_flags & QR_NETWORK)
430 || ((strcasecmp(ChrPtr(HdrLine), serv_info.serv_nodename)
431 && (strcasecmp(ChrPtr(HdrLine), serv_info.serv_fqdn)))))) {
432 FreeStrBuf(&Msg->OtherNode);
433 Msg->OtherNode = NewStrBufDup(HdrLine);
436 void tmplput_MAIL_SUMM_OTHERNODE(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
438 message_summary *Msg = (message_summary*) Context;
439 StrBufAppendBuf(Target, Msg->OtherNode, 0);
441 int Conditional_MAIL_SUMM_OTHERNODE(WCTemplateToken *Tokens, void *Context, int ContextType)
443 message_summary *Msg = (message_summary*) Context;
444 return StrLength(Msg->OtherNode) > 0;
448 void examine_rcpt(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
450 FreeStrBuf(&Msg->to);
451 Msg->to = NewStrBufPlain(NULL, StrLength(HdrLine));
452 StrBuf_RFC822_to_Utf8(Msg->to, HdrLine, WC->DefaultCharset, FoundCharset);
453 if (Msg->AllRcpt == NULL)
454 Msg->AllRcpt = NewStrBufPlain(NULL, StrLength(HdrLine));
455 if (StrLength(Msg->AllRcpt) > 0) {
456 StrBufAppendBufPlain(Msg->AllRcpt, HKEY(", "), 0);
458 StrBufAppendBuf(Msg->AllRcpt, Msg->to, 0);
460 void tmplput_MAIL_SUMM_TO(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
462 message_summary *Msg = (message_summary*) Context;
463 StrBufAppendBuf(Target, Msg->to, 0);
465 void tmplput_MAIL_SUMM_ALLRCPT(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
467 message_summary *Msg = (message_summary*) Context;
468 StrBufAppendBuf(Target, Msg->AllRcpt, 0);
473 void examine_time(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
475 Msg->date = StrTol(HdrLine);
477 void tmplput_MAIL_SUMM_DATE_STR(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
480 message_summary *Msg = (message_summary*) Context;
481 webcit_fmt_date(datebuf, Msg->date, 1);
482 StrBufAppendBufPlain(Target, datebuf, -1, 0);
484 void tmplput_MAIL_SUMM_DATE_NO(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
486 message_summary *Msg = (message_summary*) Context;
487 StrBufAppendPrintf(Target, "%ld", Msg->date, 0);
492 void examine_mime_part(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
494 wc_mime_attachment *mime;
497 mime = (wc_mime_attachment*) malloc(sizeof(wc_mime_attachment));
498 memset(mime, 0, sizeof(wc_mime_attachment));
501 mime->Name = NewStrBuf();
502 StrBufExtract_token(mime->Name, HdrLine, 0, '|');
504 StrBufExtract_token(Buf, HdrLine, 1, '|');
505 mime->FileName = NewStrBuf();
506 StrBuf_RFC822_to_Utf8(mime->FileName, Buf, WC->DefaultCharset, FoundCharset);
508 mime->PartNum = NewStrBuf();
509 StrBufExtract_token(mime->PartNum, HdrLine, 2, '|');
511 mime->Disposition = NewStrBuf();
512 StrBufExtract_token(mime->Disposition, HdrLine, 3, '|');
514 mime->ContentType = NewStrBuf();
515 StrBufExtract_token(mime->ContentType, HdrLine, 4, '|');
517 mime->length = StrBufExtract_int(HdrLine, 5, '|');
519 StrBufTrim(mime->Name);
520 StrBufTrim(mime->FileName);
522 if ( (StrLength(mime->FileName) == 0) && (StrLength(mime->Name) > 0) ) {
523 StrBufAppendBuf(mime->FileName, mime->Name, 0);
526 if (Msg->AllAttach == NULL)
527 Msg->AllAttach = NewHash(1,NULL);
528 Put(Msg->AllAttach, SKEY(mime->PartNum), mime, DestroyMime);
530 if (!strcasecmp(ChrPtr(mime->ContentType), "message/rfc822")) {
531 if (Msg->Submessages == NULL)
532 Msg->Submessages = NewHash(1,NULL);
533 Put(Msg->Submessages, SKEY(mime->PartNum), mime, reference_free_handler);
535 else if ((!strcasecmp(ChrPtr(mime->Disposition), "inline"))
536 && (!strncasecmp(ChrPtr(mime->ContentType), "image/", 6)) ){
537 if (Msg->AttachLinks == NULL)
538 Msg->AttachLinks = NewHash(1,NULL);
539 Put(Msg->AttachLinks, SKEY(mime->PartNum), mime, reference_free_handler);
541 else if ((StrLength(mime->ContentType) > 0) &&
542 ( (!strcasecmp(ChrPtr(mime->Disposition), "attachment"))
543 || (!strcasecmp(ChrPtr(mime->Disposition), "inline"))
544 || (!strcasecmp(ChrPtr(mime->Disposition), ""))))
547 if (Msg->AttachLinks == NULL)
548 Msg->AttachLinks = NewHash(1,NULL);
549 Put(Msg->AttachLinks, SKEY(mime->PartNum), mime, reference_free_handler);
550 if (strcasecmp(ChrPtr(mime->ContentType), "application/octet-stream") == 0) {
551 FlushStrBuf(mime->ContentType);
552 StrBufAppendBufPlain(mime->ContentType,
553 GuessMimeByFilename(SKEY(mime->FileName)),
558 /** begin handler prep ** */
559 if ( (!strcasecmp(ChrPtr(mime->ContentType), "text/x-vcard"))
560 || (!strcasecmp(ChrPtr(mime->ContentType), "text/vcard")) ) {
561 Msg->vcard_partnum_ref = mime;
563 else if ( (!strcasecmp(ChrPtr(mime->ContentType), "text/calendar"))
564 || (!strcasecmp(ChrPtr(mime->ContentType), "application/ics")) ) {
565 Msg->cal_partnum_ref = mime;
567 /** end handler prep ***/
572 void tmplput_MAIL_SUMM_NATTACH(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
574 message_summary *Msg = (message_summary*) Context;
575 StrBufAppendPrintf(Target, "%ld", GetCount(Msg->Attachments));
584 void examine_hnod(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
586 FreeStrBuf(&Msg->hnod);
587 Msg->hnod = NewStrBufPlain(NULL, StrLength(HdrLine));
588 StrBuf_RFC822_to_Utf8(Msg->hnod, HdrLine, WC->DefaultCharset, FoundCharset);
590 void tmplput_MAIL_SUMM_H_NODE(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
592 message_summary *Msg = (message_summary*) Context;
593 StrBufAppendBuf(Target, Msg->hnod, 0);
595 int Conditional_MAIL_SUMM_H_NODE(WCTemplateToken *Tokens, void *Context, int ContextType)
597 message_summary *Msg = (message_summary*) Context;
598 return StrLength(Msg->hnod) > 0;
603 void examine_text(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
604 {////TODO: read messages here
605 Msg->MsgBody.Data = NewStrBuf();
608 void examine_msg4_partnum(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
610 Msg->MsgBody.PartNum = NewStrBufDup(HdrLine);
611 StrBufTrim(Msg->MsgBody.PartNum);/////TODO: striplt == trim?
614 void examine_content_encoding(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
616 ////TODO: do we care?
619 void examine_content_lengh(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
621 Msg->MsgBody.length = StrTol(HdrLine);
622 Msg->MsgBody.size_known = 1;
625 void examine_content_type(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
628 Msg->MsgBody.ContentType = NewStrBufDup(HdrLine);
629 StrBufTrim(Msg->MsgBody.ContentType);/////todo==striplt?
630 len = StrLength(Msg->MsgBody.ContentType);
631 for (i=0; i<len; ++i) {
632 if (!strncasecmp(ChrPtr(Msg->MsgBody.ContentType) + i, "charset=", 8)) {/// TODO: WHUT?
633 // safestrncpy(mime_charset, &mime_content_type[i+8],
634 /// sizeof mime_charset);
637 for (i=0; i<len; ++i) {
638 if (mime_content_type[i] == ';') {
639 mime_content_type[i] = 0;
643 len = strlen(mime_charset);
644 for (i=0; i<len; ++i) {
645 if (mime_charset[i] == ';') {
653 void tmplput_MAIL_SUMM_N(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
655 message_summary *Msg = (message_summary*) Context;
656 StrBufAppendPrintf(Target, "%ld", Msg->msgnum);
660 int Conditional_MAIL_SUMM_UNREAD(WCTemplateToken *Tokens, void *Context, int ContextType)
662 message_summary *Msg = (message_summary*) Context;
663 return Msg->is_new != 0;
668 /*----------------------------------------------------------------------------*/
671 void tmplput_MAIL_BODY(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
673 message_summary *Msg = (message_summary*) Context;
674 StrBufAppendBuf(Target, Msg->MsgBody.Data, 0);
678 void render_MAIL_variformat(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCharset)
680 /* Messages in legacy Citadel variformat get handled thusly... */
681 StrBuf *Target = NewStrBufPlain(NULL, StrLength(Mime->Data));
682 FmOut(Target, "JUSTIFY", Mime->Data);
683 FreeStrBuf(&Mime->Data);
687 void render_MAIL_text_plain(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCharset)
690 const char *ptr, *pte;
691 const char *BufPtr = NULL;
692 StrBuf *Line = NewStrBuf();
693 StrBuf *Line1 = NewStrBuf();
694 StrBuf *Line2 = NewStrBuf();
695 StrBuf *Target = NewStrBufPlain(NULL, StrLength(Mime->Data));
702 iconv_t ic = (iconv_t)(-1) ;
705 /* Boring old 80-column fixed format text gets handled this way... */
706 if ((strcasecmp(ChrPtr(Mime->Charset), "us-ascii") == 0) &&
707 (strcasecmp(ChrPtr(Mime->Charset), "UTF-8") == 0))
712 if (StrLength(Mime->Charset) != 0)
714 else if (StrLength(FoundCharset) > 0)
716 else if (StrLength(WC->DefaultCharset) > 0)
717 cs = WC->DefaultCharset;
722 ctdl_iconv_open("UTF-8", ChrPtr(cs), &ic);
723 if (ic == (iconv_t)(-1) ) {
724 lprintf(5, "%s:%d iconv_open(UTF-8, %s) failed: %s\n",
725 __FILE__, __LINE__, ChrPtr(Mime->Charset), strerror(errno));
731 while ((n = StrBufSipLine(Line, Mime->Data, &BufPtr), n >= 0) && !done)
737 len = StrLength(Line);
740 while ((ptr < pte) &&
749 if (i > 0) StrBufCutLeft(Line, i);
751 if (StrLength(Line) == 0)
754 for (i = bn; i < bq; i++)
755 StrBufAppendBufPlain(Target, HKEY("<blockquote>"), 0);
756 for (i = bq; i < bn; i++)
757 StrBufAppendBufPlain(Target, HKEY("</blockquote>"), 0);
759 if (ConvertIt == 1) {
760 StrBufConvert(Line, Line1, &ic);
763 StrBufAppendBufPlain(Target, HKEY("<tt>"), 0);
764 UrlizeText(Line1, Line, Line2);
766 StrEscAppend(Target, Line1, NULL, 0, 0);
767 StrBufAppendBufPlain(Target, HKEY("</tt><br />\n"), 0);
771 for (i = 0; i < bn; i++)
772 StrBufAppendBufPlain(Target, HKEY("</blockquote>"), 0);
774 StrBufAppendBufPlain(Target, HKEY("</i><br />"), 0);
776 if (ic != (iconv_t)(-1) ) {
780 FreeStrBuf(&Mime->Data);
787 void render_MAIL_html(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCharset)
790 /* HTML is fun, but we've got to strip it first */
791 Buf = NewStrBufPlain(NULL, StrLength(Mime->Data));
792 output_html(ChrPtr(Mime->Charset),
793 (WC->wc_view == VIEW_WIKI ? 1 : 0),
794 StrToi(Mime->PartNum),
796 FreeStrBuf(&Mime->Data);
800 void render_MAIL_UNKNOWN(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCharset)
802 /* Unknown weirdness */
803 FlushStrBuf(Mime->Data);
804 StrBufAppendBufPlain(Mime->Data, _("I don't know how to display "), -1, 0);
805 StrBufAppendBuf(Mime->Data, Mime->ContentType, 0);
806 StrBufAppendBufPlain(Mime->Data, HKEY("<br />\n"), 0);
814 HashList *iterate_get_mime_All(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
816 message_summary *Msg = (message_summary*) Context;
817 return Msg->AllAttach;
819 HashList *iterate_get_mime_Submessages(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
821 message_summary *Msg = (message_summary*) Context;
822 return Msg->Submessages;
824 HashList *iterate_get_mime_AttachLinks(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
826 message_summary *Msg = (message_summary*) Context;
827 return Msg->AttachLinks;
829 HashList *iterate_get_mime_Attachments(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
831 message_summary *Msg = (message_summary*) Context;
832 return Msg->AllAttach;
836 void tmplput_MIME_ATTACH(StrBuf *TemplBuffer, void *Context, WCTemplateToken *Token)
845 * Look for URL's embedded in a buffer and make them linkable. We use a
846 * target window in order to keep the Citadel session in its own window.
848 void UrlizeText(StrBuf* Target, StrBuf *Source, StrBuf *WrkBuf)
850 int len, UrlLen, Offset, TrailerLen;
851 const char *start, *end, *pos;
856 len = StrLength(Source);
857 end = ChrPtr(Source) + len;
858 for (pos = ChrPtr(Source); (pos < end) && (start == NULL); ++pos) {
859 if (!strncasecmp(pos, "http://", 7))
861 if (!strncasecmp(pos, "ftp://", 6))
866 StrBufAppendBuf(Target, Source, 0);
871 for (pos = ChrPtr(Source) + len; pos > start; --pos) {
872 if ( (!isprint(*pos))
891 UrlLen = end - start;
892 StrBufAppendBufPlain(WrkBuf, start, UrlLen, 0);
894 Offset = start - ChrPtr(Source);
896 StrBufAppendBufPlain(Target, ChrPtr(Source), Offset, 0);
897 StrBufAppendPrintf(Target, "%ca href=%c%s%c TARGET=%c%s%c%c%s%c/A%c",
898 LB, QU, ChrPtr(WrkBuf), QU, QU, TARGET,
899 QU, RB, ChrPtr(WrkBuf), LB, RB);
901 TrailerLen = len - (end - start);
903 StrBufAppendBufPlain(Target, end, TrailerLen, 0);
905 void url(char *buf, size_t bufsize)
907 int len, UrlLen, Offset, TrailerLen, outpos;
908 char *start, *end, *pos;
915 lprintf(1, "URL: content longer than buffer!");
919 for (pos = buf; (pos < end) && (start == NULL); ++pos) {
920 if (!strncasecmp(pos, "http://", 7))
922 if (!strncasecmp(pos, "ftp://", 6))
929 for (pos = buf+len; pos > start; --pos) {
930 if ( (!isprint(*pos))
949 UrlLen = end - start;
950 if (UrlLen > sizeof(urlbuf)){
951 lprintf(1, "URL: content longer than buffer!");
954 memcpy(urlbuf, start, UrlLen);
955 urlbuf[UrlLen] = '\0';
957 Offset = start - buf;
958 if ((Offset != 0) && (Offset < sizeof(outbuf)))
959 memcpy(outbuf, buf, Offset);
960 outpos = snprintf(&outbuf[Offset], sizeof(outbuf) - Offset,
961 "%ca href=%c%s%c TARGET=%c%s%c%c%s%c/A%c",
962 LB, QU, urlbuf, QU, QU, TARGET, QU, RB, urlbuf, LB, RB);
963 if (outpos >= sizeof(outbuf) - Offset) {
964 lprintf(1, "URL: content longer than buffer!");
968 TrailerLen = len - (end - start);
970 memcpy(outbuf + Offset + outpos, end, TrailerLen);
971 if (Offset + outpos + TrailerLen > bufsize) {
972 lprintf(1, "URL: content longer than buffer!");
975 memcpy (buf, outbuf, Offset + outpos + TrailerLen);
976 *(buf + Offset + outpos + TrailerLen) = '\0';
981 * \brief Turn a vCard "n" (name) field into something displayable.
982 * \param name the name field to convert
984 void vcard_n_prettyize(char *name)
989 original_name = strdup(name);
990 len = strlen(original_name);
991 for (i=0; i<5; ++i) {
993 if (original_name[len-1] == ' ') {
994 original_name[--len] = 0;
996 if (original_name[len-1] == ';') {
997 original_name[--len] = 0;
1003 for (i=0; i<len; ++i) {
1004 if (original_name[i] == ';') {
1009 name[j++] = original_name[i];
1013 free(original_name);
1020 * \brief preparse a vcard name
1021 * display_vcard() calls this after parsing the textual vCard into
1022 * our 'struct vCard' data object.
1023 * This gets called instead of display_parsed_vcard() if we are only looking
1024 * to extract the person's name instead of displaying the card.
1025 * \param v the vcard to retrieve the name from
1026 * \param storename where to put the name at
1028 void fetchname_parsed_vcard(struct vCard *v, char *storename) {
1031 strcpy(storename, "");
1033 name = vcard_get_prop(v, "n", 1, 0, 0);
1035 strcpy(storename, name);
1036 /* vcard_n_prettyize(storename); */
1044 * \brief html print a vcard
1045 * display_vcard() calls this after parsing the textual vCard into
1046 * our 'struct vCard' data object.
1048 * Set 'full' to nonzero to display the full card, otherwise it will only
1049 * show a summary line.
1051 * This code is a bit ugly, so perhaps an explanation is due: we do this
1052 * in two passes through the vCard fields. On the first pass, we process
1053 * fields we understand, and then render them in a pretty fashion at the
1054 * end. Then we make a second pass, outputting all the fields we don't
1055 * understand in a simple two-column name/value format.
1056 * \param v the vCard to display
1057 * \param full display all items of the vcard?
1058 * \param msgnum Citadel message pointer
1060 void display_parsed_vcard(struct vCard *v, int full, long msgnum) {
1066 char *thisname, *thisvalue;
1067 char firsttoken[SIZ];
1076 strcpy(fullname, "");
1084 name = vcard_get_prop(v, "fn", 1, 0, 0);
1088 else if (name = vcard_get_prop(v, "n", 1, 0, 0), name != NULL) {
1089 strcpy(fullname, name);
1090 vcard_n_prettyize(fullname);
1100 wprintf("<div align=center>"
1101 "<table bgcolor=#aaaaaa width=50%%>");
1102 for (pass=1; pass<=2; ++pass) {
1104 if (v->numprops) for (i=0; i<(v->numprops); ++i) {
1106 thisname = strdup(v->prop[i].name);
1107 extract_token(firsttoken, thisname, 0, ';', sizeof firsttoken);
1109 for (j=0; j<num_tokens(thisname, ';'); ++j) {
1110 extract_token(buf, thisname, j, ';', sizeof buf);
1111 if (!strcasecmp(buf, "encoding=quoted-printable")) {
1113 remove_token(thisname, j, ';');
1115 if (!strcasecmp(buf, "encoding=base64")) {
1117 remove_token(thisname, j, ';');
1121 len = strlen(v->prop[i].value);
1122 /* if we have some untagged QP, detect it here. */
1123 if (!is_qp && (strstr(v->prop[i].value, "=?")!=NULL))
1124 utf8ify_rfc822_string(v->prop[i].value);
1127 // %ff can become 6 bytes in utf8
1128 thisvalue = malloc(len * 2 + 3);
1129 j = CtdlDecodeQuotedPrintable(
1130 thisvalue, v->prop[i].value,
1135 // ff will become one byte..
1136 thisvalue = malloc(len + 50);
1138 thisvalue, v->prop[i].value,
1139 strlen(v->prop[i].value) );
1142 thisvalue = strdup(v->prop[i].value);
1145 /** Various fields we may encounter ***/
1147 /** N is name, but only if there's no FN already there */
1148 if (!strcasecmp(firsttoken, "n")) {
1149 if (IsEmptyStr(fullname)) {
1150 strcpy(fullname, thisvalue);
1151 vcard_n_prettyize(fullname);
1155 /** FN (full name) is a true 'display name' field */
1156 else if (!strcasecmp(firsttoken, "fn")) {
1157 strcpy(fullname, thisvalue);
1161 else if (!strcasecmp(firsttoken, "title")) {
1162 strcpy(title, thisvalue);
1166 else if (!strcasecmp(firsttoken, "org")) {
1167 strcpy(org, thisvalue);
1170 else if (!strcasecmp(firsttoken, "email")) {
1172 if (!IsEmptyStr(mailto)) strcat(mailto, "<br />");
1174 "<a href=\"display_enter"
1175 "?force_room=_MAIL_?recp=");
1177 len = strlen(mailto);
1178 urlesc(&mailto[len], SIZ - len, "\"");
1179 len = strlen(mailto);
1180 urlesc(&mailto[len], SIZ - len, fullname);
1181 len = strlen(mailto);
1182 urlesc(&mailto[len], SIZ - len, "\" <");
1183 len = strlen(mailto);
1184 urlesc(&mailto[len], SIZ - len, thisvalue);
1185 len = strlen(mailto);
1186 urlesc(&mailto[len], SIZ - len, ">");
1188 strcat(mailto, "\">");
1189 len = strlen(mailto);
1190 stresc(mailto+len, SIZ - len, thisvalue, 1, 1);
1191 strcat(mailto, "</A>");
1193 else if (!strcasecmp(firsttoken, "tel")) {
1194 if (!IsEmptyStr(phone)) strcat(phone, "<br />");
1195 strcat(phone, thisvalue);
1196 for (j=0; j<num_tokens(thisname, ';'); ++j) {
1197 extract_token(buf, thisname, j, ';', sizeof buf);
1198 if (!strcasecmp(buf, "tel"))
1200 else if (!strcasecmp(buf, "work"))
1201 strcat(phone, _(" (work)"));
1202 else if (!strcasecmp(buf, "home"))
1203 strcat(phone, _(" (home)"));
1204 else if (!strcasecmp(buf, "cell"))
1205 strcat(phone, _(" (cell)"));
1207 strcat(phone, " (");
1213 else if (!strcasecmp(firsttoken, "adr")) {
1215 wprintf("<TR><TD>");
1216 wprintf(_("Address:"));
1217 wprintf("</TD><TD>");
1218 for (j=0; j<num_tokens(thisvalue, ';'); ++j) {
1219 extract_token(buf, thisvalue, j, ';', sizeof buf);
1220 if (!IsEmptyStr(buf)) {
1222 if (j<3) wprintf("<br />");
1226 wprintf("</TD></TR>\n");
1229 /* else if (!strcasecmp(firsttoken, "photo") && full && pass == 2) {
1230 // Only output on second pass
1231 wprintf("<tr><td>");
1232 wprintf(_("Photo:"));
1233 wprintf("</td><td>");
1234 wprintf("<img src=\"/vcardphoto/%ld/\" alt=\"Contact photo\"/>",msgnum);
1235 wprintf("</td></tr>\n");
1237 else if (!strcasecmp(firsttoken, "version")) {
1240 else if (!strcasecmp(firsttoken, "rev")) {
1243 else if (!strcasecmp(firsttoken, "label")) {
1248 /*** Don't show extra fields. They're ugly.
1250 wprintf("<TR><TD>");
1252 wprintf("</TD><TD>");
1254 wprintf("</TD></TR>\n");
1264 wprintf("<TR BGCOLOR=\"#AAAAAA\">"
1265 "<TD COLSPAN=2 BGCOLOR=\"#FFFFFF\">"
1266 "<IMG ALIGN=CENTER src=\"static/viewcontacts_48x.gif\">"
1267 "<FONT SIZE=+1><B>");
1269 wprintf("</B></FONT>");
1270 if (!IsEmptyStr(title)) {
1271 wprintf("<div align=right>");
1275 if (!IsEmptyStr(org)) {
1276 wprintf("<div align=right>");
1280 wprintf("</TD></TR>\n");
1282 if (!IsEmptyStr(phone)) {
1283 wprintf("<tr><td>");
1284 wprintf(_("Telephone:"));
1285 wprintf("</td><td>%s</td></tr>\n", phone);
1287 if (!IsEmptyStr(mailto)) {
1288 wprintf("<tr><td>");
1289 wprintf(_("E-mail:"));
1290 wprintf("</td><td>%s</td></tr>\n", mailto);
1296 wprintf("</table></div>\n");
1302 * \brief Display a textual vCard
1303 * (Converts to a vCard object and then calls the actual display function)
1304 * Set 'full' to nonzero to display the whole card instead of a one-liner.
1305 * Or, if "storename" is non-NULL, just store the person's name in that
1306 * buffer instead of displaying the card at all.
1307 * \param vcard_source the buffer containing the vcard text
1308 * \param alpha what???
1309 * \param full should we usse all lines?
1310 * \param storename where to store???
1311 * \param msgnum Citadel message pointer
1313 void display_vcard(char *vcard_source, char alpha, int full, char *storename,
1318 char this_alpha = 0;
1320 v = vcard_load(vcard_source);
1321 if (v == NULL) return;
1323 name = vcard_get_prop(v, "n", 1, 0, 0);
1325 utf8ify_rfc822_string(name);
1327 this_alpha = buf[0];
1330 if (storename != NULL) {
1331 fetchname_parsed_vcard(v, storename);
1333 else if ( (alpha == 0)
1334 || ((isalpha(alpha)) && (tolower(alpha) == tolower(this_alpha)) )
1335 || ((!isalpha(alpha)) && (!isalpha(this_alpha)))
1337 display_parsed_vcard(v, full,msgnum);
1355 * I wanna SEE that message!
1357 * msgnum Message number to display
1358 * printable_view Nonzero to display a printable view
1359 * section Optional for encapsulated message/rfc822 submessage
1361 void read_message(long msgnum, int printable_view, char *section) {
1362 struct wcsession *WCC = WC;
1365 StrBuf *FoundCharset;
1366 message_summary *Msg = NULL;
1370 struct attach_link *attach_links = NULL;
1371 int num_attach_links = 0;
1372 // char mime_submessages[256] = "";
1373 char reply_references[1024] = "";
1378 char vcard_partnum[256] = "";
1379 char cal_partnum[256] = "";
1380 char *part_source = NULL;
1381 char msg4_partnum[32] = "";
1383 //// strcpy(mime_submessages, "");
1386 serv_printf("MSG4 %ld|%s", msgnum, section);
1387 StrBuf_ServGetln(Buf);
1388 if (GetServerStatus(Buf, NULL) != 1) {
1389 wprintf("<strong>");
1390 wprintf(_("ERROR:"));
1391 wprintf("</strong> %s<br />\n", &buf[4]);
1395 svputlong("MsgPrintable", printable_view);
1396 /** begin everythingamundo table */
1399 Token = NewStrBuf();
1400 Msg = (message_summary *)malloc(sizeof(message_summary));
1401 memset(Msg, 0, sizeof(message_summary));
1402 FoundCharset = NewStrBuf();
1403 while ((StrBuf_ServGetln(Buf)>=0) && !Done) {
1404 if ( (StrLength(Buf)==3) &&
1405 !strcmp(ChrPtr(Buf), "000"))
1410 wprintf(_("unexpected end of message"));
1411 wprintf(" (1)</i><br /><br />\n");
1412 wprintf("</div>\n");
1415 DestroyMessageSummary(Msg);
1416 FreeStrBuf(&FoundCharset);
1424 case 0:/* Citadel Message Headers */
1425 if (StrLength(Buf) == 0) {
1429 StrBufExtract_token(Token, Buf, 0, '=');
1430 StrBufCutLeft(Buf, StrLength(Token) + 1);
1432 lprintf(1, ":: [%s] = [%s]\n", ChrPtr(Token), ChrPtr(Buf));
1433 if (GetHash(MsgHeaderHandler, SKEY(Token), &vHdr) &&
1435 Hdr = (headereval*)vHdr;
1436 Hdr->evaluator(Msg, Buf, FoundCharset);
1437 if (Hdr->Type == 1) {
1441 else lprintf(1, "don't know how to handle message header[%s]\n", ChrPtr(Token));
1443 case 1:/* Message Mime Header */
1444 if (StrLength(Buf) == 0) {
1446 if (Msg->MsgBody.ContentType == NULL)
1447 /* end of header or no header? */
1448 Msg->MsgBody.ContentType = NewStrBufPlain(HKEY("text/plain"));
1449 /* usual end of mime header */
1453 StrBufExtract_token(Token, Buf, 0, ':');
1454 if (StrLength(Token) > 0) {
1455 StrBufCutLeft(Buf, StrLength(Token) + 1);
1456 lprintf(1, ":: [%s] = [%s]\n", ChrPtr(Token), ChrPtr(Buf));
1457 if (GetHash(MsgHeaderHandler, SKEY(Token), &vHdr) &&
1459 Hdr = (headereval*)vHdr;
1460 Hdr->evaluator(Msg, Buf, FoundCharset);
1465 case 2: /* Message Body */
1467 if (Msg->MsgBody.size_known > 0) {
1468 StrBuf_ServGetBLOB(Msg->MsgBody.Data, Msg->MsgBody.length);
1470 /// todo: check next line, if not 000, append following lines
1473 if (StrLength(Msg->MsgBody.Data) > 0)
1474 StrBufAppendBufPlain(Msg->MsgBody.Data, "\n", 1, 0);
1475 StrBufAppendBuf(Msg->MsgBody.Data, Buf, 0);
1479 StrBufAppendBuf(Msg->MsgBody.Data, Buf, 0);
1484 /* strip the bare contenttype, so we ommit charset etc. */
1485 StrBufExtract_token(Buf, Msg->MsgBody.ContentType, 0, ';');
1487 if (GetHash(MimeRenderHandler, SKEY(Buf), &vHdr) &&
1489 RenderMimeFunc Render;
1490 Render = (RenderMimeFunc)vHdr;
1491 Render(&Msg->MsgBody, NULL, FoundCharset);
1495 if (StrLength(Msg->reply_references)> 0) {
1496 /* Trim down excessively long lists of thread references. We eliminate the
1497 * second one in the list so that the thread root remains intact.
1499 int rrtok = num_tokens(ChrPtr(Msg->reply_references), '|');
1500 int rrlen = StrLength(Msg->reply_references);
1501 if ( ((rrtok >= 3) && (rrlen > 900)) || (rrtok > 10) ) {
1502 remove_token(reply_references, 1, '|');////todo
1506 /* Generate a reply-to address */
1507 if (StrLength(Msg->Rfca) > 0) {
1508 if (Msg->reply_to == NULL)
1509 Msg->reply_to = NewStrBuf();
1510 if (StrLength(Msg->from) > 0) {
1511 StrBufPrintf(Msg->reply_to, "%s <%s>", ChrPtr(Msg->from), ChrPtr(Msg->Rfca));
1514 FlushStrBuf(Msg->reply_to);
1515 StrBufAppendBuf(Msg->reply_to, Msg->Rfca, 0);
1520 if ((StrLength(Msg->OtherNode)>0) &&
1521 (strcasecmp(ChrPtr(Msg->OtherNode), serv_info.serv_nodename)) &&
1522 (strcasecmp(ChrPtr(Msg->OtherNode), serv_info.serv_humannode)) )
1524 if (Msg->reply_to == NULL)
1525 Msg->reply_to = NewStrBuf();
1526 StrBufPrintf(Msg->reply_to,
1529 ChrPtr(Msg->OtherNode));
1532 if (Msg->reply_to == NULL)
1533 Msg->reply_to = NewStrBuf();
1534 FlushStrBuf(Msg->reply_to);
1535 StrBufAppendBuf(Msg->reply_to, Msg->from, 0);
1542 DoTemplate(HKEY("view_message"), NULL, Msg, CTX_MAILSUM);
1546 //// put message renderer lookup here.
1547 ///ENDBODY: /* If there are attached submessages, display them now... */
1549 /// if ( (!IsEmptyStr(mime_submessages)) && (!section[0]) ) {
1550 /// for (i=0; i<num_tokens(mime_submessages, '|'); ++i) {
1551 /// extract_token(buf, mime_submessages, i, '|', sizeof buf);
1552 /// /** use printable_view to suppress buttons */
1553 /// wprintf("<blockquote>");
1554 /// read_message(msgnum, 1, buf);
1555 /// wprintf("</blockquote>");
1560 /* Afterwards, offer links to download attachments 'n' such */
1561 if ( (num_attach_links > 0) && (!section[0]) ) {
1562 for (i=0; i<num_attach_links; ++i) {
1563 if (strcasecmp(attach_links[i].partnum, msg4_partnum)) {
1564 wprintf("%s", attach_links[i].html);
1569 /* Handler for vCard parts */
1570 if (!IsEmptyStr(vcard_partnum)) {
1571 part_source = load_mimepart(msgnum, vcard_partnum);
1572 if (part_source != NULL) {
1574 /** If it's my vCard I can edit it */
1575 if ( (!strcasecmp(WC->wc_roomname, USERCONFIGROOM))
1576 || (!strcasecmp(&WC->wc_roomname[11], USERCONFIGROOM))
1577 || (WC->wc_view == VIEW_ADDRESSBOOK)
1579 wprintf("<a href=\"edit_vcard?msgnum=%ld&partnum=%s\">",
1580 msgnum, vcard_partnum);
1581 wprintf("[%s]</a>", _("edit"));
1584 /* In all cases, display the full card */
1585 display_vcard(part_source, 0, 1, NULL,msgnum);
1589 /* Handler for calendar parts */
1590 if (!IsEmptyStr(cal_partnum)) {
1591 part_source = load_mimepart(msgnum, cal_partnum);
1592 if (part_source != NULL) {
1593 cal_process_attachment(part_source, msgnum, cal_partnum);
1602 wprintf("</div>\n");
1604 /* end everythingamundo table */
1605 if (!printable_view) {
1606 wprintf("</div>\n");
1609 if (num_attach_links > 0) {
1612 DestroyMessageSummary(Msg);
1613 FreeStrBuf(&FoundCharset);
1621 * Unadorned HTML output of an individual message, suitable
1622 * for placing in a hidden iframe, for printing, or whatever
1624 * msgnum_as_string == Message number, as a string instead of as a long int
1626 void embed_message(void) {
1629 msgnum = StrTol(WC->UrlFragment1);
1630 read_message(msgnum, 0, "");
1635 * Printable view of a message
1637 * msgnum_as_string == Message number, as a string instead of as a long int
1639 void print_message(void) {
1642 msgnum = StrTol(WC->UrlFragment1);
1643 output_headers(0, 0, 0, 0, 0, 0);
1645 hprintf("Content-type: text/html\r\n"
1647 "Connection: close\r\n",
1651 wprintf("\r\n<html>\n<head><title>");
1652 escputs(WC->wc_fullname);
1653 wprintf("</title></head>\n"
1654 "<body onLoad=\" window.print(); window.close(); \">\n"
1657 read_message(msgnum, 1, "");
1659 wprintf("\n</body></html>\n\n");
1664 * Mobile browser view of message
1666 * @param msg_num_as_string Message number as a string instead of as a long int
1668 void mobile_message_view(void) {
1670 msgnum = StrTol(WC->UrlFragment1);
1671 output_headers(1, 0, 0, 0, 0, 1);
1673 do_template("msgcontrols", NULL);
1674 read_message(msgnum,1, "");
1679 * \brief Display a message's headers
1681 * \param msgnum_as_string Message number, as a string instead of as a long int
1683 void display_headers(void) {
1687 msgnum = StrTol(WC->UrlFragment1);
1688 output_headers(0, 0, 0, 0, 0, 0);
1690 hprintf("Content-type: text/plain\r\n"
1692 "Connection: close\r\n",
1696 serv_printf("MSG2 %ld|3", msgnum);
1697 serv_getln(buf, sizeof buf);
1698 if (buf[0] == '1') {
1699 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1700 wprintf("%s\n", buf);
1710 * \brief Read message in simple, JavaScript-embeddable form for 'forward'
1711 * or 'reply quoted' operations.
1713 * NOTE: it is VITALLY IMPORTANT that we output no single-quotes or linebreaks
1714 * in this function. Doing so would throw a JavaScript error in the
1715 * 'supplied text' argument to the editor.
1717 * \param msgnum Message number of the message we want to quote
1718 * \param forward_attachments Nonzero if we want attachments to be forwarded
1720 void pullquote_message(long msgnum, int forward_attachments, int include_headers) {
1722 char mime_partnum[256];
1723 char mime_filename[256];
1724 char mime_content_type[256];
1725 char mime_charset[256];
1726 char mime_disposition[256];
1728 char *attachments = NULL;
1730 int num_attachments = 0;
1731 struct wc_attachment *att, *aptr;
1732 char m_subject[1024];
1739 int format_type = 0;
1744 iconv_t ic = (iconv_t)(-1) ;
1745 char *ibuf; /**< Buffer of characters to be converted */
1746 char *obuf; /**< Buffer for converted characters */
1747 size_t ibuflen; /**< Length of input buffer */
1748 size_t obuflen; /**< Length of output buffer */
1749 char *osav; /**< Saved pointer to output buffer */
1755 strcpy(reply_to, "");
1756 strcpy(mime_content_type, "text/plain");
1757 strcpy(mime_charset, "us-ascii");
1759 serv_printf("MSG4 %ld", msgnum);
1760 serv_getln(buf, sizeof buf);
1761 if (buf[0] != '1') {
1762 wprintf(_("ERROR:"));
1763 wprintf("%s<br />", &buf[4]);
1767 strcpy(m_subject, "");
1769 while (serv_getln(buf, sizeof buf), strcasecmp(buf, "text")) {
1770 if (!strcmp(buf, "000")) {
1771 wprintf("%s (3)", _("unexpected end of message"));
1774 if (include_headers) {
1775 if (!strncasecmp(buf, "nhdr=yes", 8))
1779 if (!strncasecmp(buf, "type=", 5))
1780 format_type = atoi(&buf[5]);
1781 if (!strncasecmp(buf, "from=", 5)) {
1782 strcpy(from, &buf[5]);
1783 wprintf(_("from "));
1784 utf8ify_rfc822_string(from);
1787 if (!strncasecmp(buf, "subj=", 5)) {
1788 strcpy(m_subject, &buf[5]);
1790 if ((!strncasecmp(buf, "hnod=", 5))
1791 && (strcasecmp(&buf[5], serv_info.serv_humannode))) {
1792 wprintf("(%s) ", &buf[5]);
1794 if ((!strncasecmp(buf, "room=", 5))
1795 && (strcasecmp(&buf[5], WC->wc_roomname))
1796 && (!IsEmptyStr(&buf[5])) ) {
1798 wprintf("%s> ", &buf[5]);
1800 if (!strncasecmp(buf, "rfca=", 5)) {
1801 strcpy(rfca, &buf[5]);
1806 if (!strncasecmp(buf, "node=", 5)) {
1807 strcpy(node, &buf[5]);
1808 if ( ((WC->room_flags & QR_NETWORK)
1809 || ((strcasecmp(&buf[5], serv_info.serv_nodename)
1810 && (strcasecmp(&buf[5], serv_info.serv_fqdn)))))
1811 && (IsEmptyStr(rfca))
1813 wprintf("@%s ", &buf[5]);
1816 if (!strncasecmp(buf, "rcpt=", 5)) {
1818 strcpy(to, &buf[5]);
1819 utf8ify_rfc822_string(to);
1822 if (!strncasecmp(buf, "time=", 5)) {
1823 webcit_fmt_date(now, atol(&buf[5]), 0);
1824 wprintf("%s ", now);
1829 * Save attachment info for later. We can't start downloading them
1830 * yet because we're in the middle of a server transaction.
1832 if (!strncasecmp(buf, "part=", 5)) {
1833 ptr = malloc( (strlen(buf) + ((attachments != NULL) ? strlen(attachments) : 0)) ) ;
1836 sprintf(ptr, "%s%s\n",
1837 ((attachments != NULL) ? attachments : ""),
1842 lprintf(9, "attachments=<%s>\n", attachments);
1848 if (include_headers) {
1851 utf8ify_rfc822_string(m_subject);
1852 if (!IsEmptyStr(m_subject)) {
1853 wprintf(_("Subject:"));
1855 msgescputs(m_subject);
1866 * Learn the content type
1868 strcpy(mime_content_type, "text/plain");
1869 while (serv_getln(buf, sizeof buf), (!IsEmptyStr(buf))) {
1870 if (!strcmp(buf, "000")) {
1871 wprintf("%s (4)", _("unexpected end of message"));
1874 if (!strncasecmp(buf, "Content-type: ", 14)) {
1876 safestrncpy(mime_content_type, &buf[14],
1877 sizeof(mime_content_type));
1878 for (i=0; i<strlen(mime_content_type); ++i) {
1879 if (!strncasecmp(&mime_content_type[i], "charset=", 8)) {
1880 safestrncpy(mime_charset, &mime_content_type[i+8],
1881 sizeof mime_charset);
1884 len = strlen(mime_content_type);
1885 for (i=0; i<len; ++i) {
1886 if (mime_content_type[i] == ';') {
1887 mime_content_type[i] = 0;
1891 len = strlen(mime_charset);
1892 for (i=0; i<len; ++i) {
1893 if (mime_charset[i] == ';') {
1894 mime_charset[i] = 0;
1901 /** Set up a character set conversion if we need to (and if we can) */
1903 if ( (strcasecmp(mime_charset, "us-ascii"))
1904 && (strcasecmp(mime_charset, "UTF-8"))
1905 && (strcasecmp(mime_charset, ""))
1907 ctdl_iconv_open("UTF-8", mime_charset, &ic);
1908 if (ic == (iconv_t)(-1) ) {
1909 lprintf(5, "%s:%d iconv_open(%s, %s) failed: %s\n",
1910 __FILE__, __LINE__, "UTF-8", mime_charset, strerror(errno));
1915 /** Messages in legacy Citadel variformat get handled thusly... */
1916 if (!strcasecmp(mime_content_type, "text/x-citadel-variformat")) {
1920 /* Boring old 80-column fixed format text gets handled this way... */
1921 else if (!strcasecmp(mime_content_type, "text/plain")) {
1922 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1925 if ((len > 0) && (buf[len-1] == '\n')) buf[--len] = 0;
1926 if ((len > 0) && (buf[len-1] == '\r')) buf[--len] = 0;
1929 if (ic != (iconv_t)(-1) ) {
1933 obuf = (char *) malloc(obuflen);
1935 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
1936 osav[SIZ-obuflen] = 0;
1937 safestrncpy(buf, osav, sizeof buf);
1943 while ((!IsEmptyStr(buf)) && (isspace(buf[len - 1])))
1946 ((!strncmp(buf, ">", 1)) || (!strncmp(buf, " >", 2)) )) {
1947 wprintf("<blockquote>");
1949 } else if ((bq == 1) &&
1950 (strncmp(buf, ">", 1)) && (strncmp(buf, " >", 2)) ) {
1951 wprintf("</blockquote>");
1955 url(buf, sizeof(buf));
1957 wprintf("</tt><br />");
1959 wprintf("</i><br />");
1962 /** HTML just gets escaped and stuffed back into the editor */
1963 else if (!strcasecmp(mime_content_type, "text/html")) {
1964 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1968 }//// TODO: charset? utf8?
1970 /** Unknown weirdness ... don't know how to handle this content type */
1972 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { }
1976 /** end of body handler */
1979 * If there were attachments, we have to download them and insert them
1980 * into the attachment chain for the forwarded message we are composing.
1982 if ( (forward_attachments) && (num_attachments) ) {
1983 for (i=0; i<num_attachments; ++i) {
1984 extract_token(buf, attachments, i, '\n', sizeof buf);
1985 extract_token(mime_filename, buf, 1, '|', sizeof mime_filename);
1986 extract_token(mime_partnum, buf, 2, '|', sizeof mime_partnum);
1987 extract_token(mime_disposition, buf, 3, '|', sizeof mime_disposition);
1988 extract_token(mime_content_type, buf, 4, '|', sizeof mime_content_type);
1989 mime_length = extract_int(buf, 5);
1992 * tracing ... uncomment if necessary
1995 lprintf(9, "fwd filename: %s\n", mime_filename);
1996 lprintf(9, "fwd partnum : %s\n", mime_partnum);
1997 lprintf(9, "fwd conttype: %s\n", mime_content_type);
1998 lprintf(9, "fwd dispose : %s\n", mime_disposition);
1999 lprintf(9, "fwd length : %d\n", mime_length);
2001 if ( (!strcasecmp(mime_disposition, "inline"))
2002 || (!strcasecmp(mime_disposition, "attachment")) ) {
2004 /* Create an attachment struct from this mime part... */
2005 att = malloc(sizeof(struct wc_attachment));
2006 memset(att, 0, sizeof(struct wc_attachment));
2007 att->length = mime_length;
2008 strcpy(att->content_type, mime_content_type);
2009 strcpy(att->filename, mime_filename);
2011 att->data = load_mimepart(msgnum, mime_partnum);
2013 /* And add it to the list. */
2014 if (WC->first_attachment == NULL) {
2015 WC->first_attachment = att;
2018 aptr = WC->first_attachment;
2019 while (aptr->next != NULL) aptr = aptr->next;
2028 if (ic != (iconv_t)(-1) ) {
2033 if (attachments != NULL) {
2041 void EvaluateMimePart(message_summary *Sum, StrBuf *Buf)
2044 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
2045 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
2046 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
2047 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
2048 mime_length = extract_int(&buf[5], 5);
2050 if ( (!strcasecmp(mime_content_type, "text/x-vcard"))
2051 || (!strcasecmp(mime_content_type, "text/vcard")) ) {
2052 strcpy(vcard_partnum, mime_partnum);
2057 message_summary *ReadOneMessageSummary(StrBuf *RawMessage, const char *DefaultSubject, long MsgNum)
2060 MsgPartEvaluatorFunc Eval;
2061 message_summary *Msg;
2070 serv_printf("MSG0 %ld|1", MsgNum); /* ask for headers only */
2072 StrBuf_ServGetln(Buf);
2073 if (GetServerStatus(Buf, NULL) == 1) {
2078 Msg = (message_summary*)malloc(sizeof(message_summary));
2079 memset(Msg, 0, sizeof(message_summary));
2080 while (len = StrBuf_ServGetln(Buf),
2082 strcmp(ChrPtr(Buf), "000")== 0)){
2084 ebuf = strchr(ChrPtr(Buf), '=');
2086 if (GetHash(MsgEvaluators, buf, nBuf, &vEval) && vEval != NULL) {
2087 Eval = (MsgPartEvaluatorFunc) vEval;
2088 StrBufCutLeft(Buf, nBuf + 1);
2091 else lprintf(1, "Don't know how to handle Message Headerline [%s]", ChrPtr(Buf));
2098 * \brief display the adressbook overview
2099 * \param msgnum the citadel message number
2100 * \param alpha what????
2102 void display_addressbook(long msgnum, char alpha) {
2104 /* char mime_partnum[SIZ]; */
2105 /* char mime_filename[SIZ]; */
2106 /* char mime_content_type[SIZ]; */
2107 ///char mime_disposition[SIZ];
2109 char vcard_partnum[SIZ];
2110 char *vcard_source = NULL;
2111 message_summary summ;////TODO: this will leak
2113 memset(&summ, 0, sizeof(summ));
2114 ///safestrncpy(summ.subj, _("(no subject)"), sizeof summ.subj);
2115 ///Load Message headers
2117 if (!IsEmptyStr(vcard_partnum)) {
2118 vcard_source = load_mimepart(msgnum, vcard_partnum);
2119 if (vcard_source != NULL) {
2121 /** Display the summary line */
2122 display_vcard(vcard_source, alpha, 0, NULL,msgnum);
2124 /** If it's my vCard I can edit it */
2125 if ( (!strcasecmp(WC->wc_roomname, USERCONFIGROOM))
2126 || (!strcasecmp(&WC->wc_roomname[11], USERCONFIGROOM))
2127 || (WC->wc_view == VIEW_ADDRESSBOOK)
2129 wprintf("<a href=\"edit_vcard?"
2130 "msgnum=%ld&partnum=%s\">",
2131 msgnum, vcard_partnum);
2132 wprintf("[%s]</a>", _("edit"));
2144 * \brief If it's an old "Firstname Lastname" style record, try to convert it.
2145 * \param namebuf name to analyze, reverse if nescessary
2147 void lastfirst_firstlast(char *namebuf) {
2148 char firstname[SIZ];
2152 if (namebuf == NULL) return;
2153 if (strchr(namebuf, ';') != NULL) return;
2155 i = num_tokens(namebuf, ' ');
2158 extract_token(lastname, namebuf, i-1, ' ', sizeof lastname);
2159 remove_token(namebuf, i-1, ' ');
2160 strcpy(firstname, namebuf);
2161 sprintf(namebuf, "%s; %s", lastname, firstname);
2165 * \brief fetch what??? name
2166 * \param msgnum the citadel message number
2167 * \param namebuf where to put the name in???
2169 void fetch_ab_name(message_summary *Msg, char *namebuf) {
2171 char mime_partnum[SIZ];
2172 char mime_filename[SIZ];
2173 char mime_content_type[SIZ];
2174 char mime_disposition[SIZ];
2176 char vcard_partnum[SIZ];
2177 char *vcard_source = NULL;
2179 message_summary summ;/// TODO this will lak
2181 if (namebuf == NULL) return;
2182 strcpy(namebuf, "");
2184 memset(&summ, 0, sizeof(summ));
2185 //////safestrncpy(summ.subj, "(no subject)", sizeof summ.subj);
2187 sprintf(buf, "MSG0 %ld|0", Msg->msgnum); /** unfortunately we need the mime info now */
2189 serv_getln(buf, sizeof buf);
2190 if (buf[0] != '1') return;
2192 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
2193 if (!strncasecmp(buf, "part=", 5)) {
2194 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
2195 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
2196 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
2197 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
2198 mime_length = extract_int(&buf[5], 5);
2200 if ( (!strcasecmp(mime_content_type, "text/x-vcard"))
2201 || (!strcasecmp(mime_content_type, "text/vcard")) ) {
2202 strcpy(vcard_partnum, mime_partnum);
2208 if (!IsEmptyStr(vcard_partnum)) {
2209 vcard_source = load_mimepart(Msg->msgnum, vcard_partnum);
2210 if (vcard_source != NULL) {
2212 /* Grab the name off the card */
2213 display_vcard(vcard_source, 0, 0, namebuf, Msg->msgnum);
2219 lastfirst_firstlast(namebuf);
2221 len = strlen(namebuf);
2222 for (i=0; i<len; ++i) {
2223 if (namebuf[i] != ';') return;
2225 strcpy(namebuf, _("(no name)"));
2231 * \brief Record compare function for sorting address book indices
2232 * \param ab1 adressbook one
2233 * \param ab2 adressbook two
2235 int abcmp(const void *ab1, const void *ab2) {
2237 (((const struct addrbookent *)ab1)->ab_name),
2238 (((const struct addrbookent *)ab2)->ab_name)
2244 * \brief Helper function for do_addrbook_view()
2245 * Converts a name into a three-letter tab label
2246 * \param tabbuf the tabbuffer to add name to
2247 * \param name the name to add to the tabbuffer
2249 void nametab(char *tabbuf, long len, char *name) {
2250 stresc(tabbuf, len, name, 0, 0);
2251 tabbuf[0] = toupper(tabbuf[0]);
2252 tabbuf[1] = tolower(tabbuf[1]);
2253 tabbuf[2] = tolower(tabbuf[2]);
2259 * \brief Render the address book using info we gathered during the scan
2260 * \param addrbook the addressbook to render
2261 * \param num_ab the number of the addressbook
2263 void do_addrbook_view(struct addrbookent *addrbook, int num_ab) {
2267 static int NAMESPERPAGE = 60;
2270 char tabfirst_label[64];
2272 char tablast_label[64];
2273 char this_tablabel[64];
2278 wprintf("<br /><br /><br /><div align=\"center\"><i>");
2279 wprintf(_("This address book is empty."));
2280 wprintf("</i></div>\n");
2285 qsort(addrbook, num_ab, sizeof(struct addrbookent), abcmp);
2288 num_pages = (num_ab / NAMESPERPAGE) + 1;
2290 tablabels = malloc(num_pages * sizeof (char *));
2291 if (tablabels == NULL) {
2292 wprintf("<br /><br /><br /><div align=\"center\"><i>");
2293 wprintf(_("An internal error has occurred."));
2294 wprintf("</i></div>\n");
2298 for (i=0; i<num_pages; ++i) {
2299 tabfirst = i * NAMESPERPAGE;
2300 tablast = tabfirst + NAMESPERPAGE - 1;
2301 if (tablast > (num_ab - 1)) tablast = (num_ab - 1);
2302 nametab(tabfirst_label, 64, addrbook[tabfirst].ab_name);
2303 nametab(tablast_label, 64, addrbook[tablast].ab_name);
2304 sprintf(this_tablabel, "%s - %s", tabfirst_label, tablast_label);
2305 tablabels[i] = strdup(this_tablabel);
2308 tabbed_dialog(num_pages, tablabels);
2311 for (i=0; i<num_ab; ++i) {
2313 if ((i / NAMESPERPAGE) != page) { /* New tab */
2314 page = (i / NAMESPERPAGE);
2316 wprintf("</tr></table>\n");
2317 end_tab(page-1, num_pages);
2319 begin_tab(page, num_pages);
2320 wprintf("<table border=0 cellspacing=0 cellpadding=3 width=100%%>\n");
2324 if ((displayed % 4) == 0) {
2325 if (displayed > 0) {
2329 wprintf("<tr bgcolor=\"#%s\">",
2330 (bg ? "DDDDDD" : "FFFFFF")
2336 wprintf("<a href=\"readfwd?startmsg=%ld?is_singlecard=1",
2337 addrbook[i].ab_msgnum);
2338 wprintf("?maxmsgs=1?is_summary=0?alpha=%s\">", bstr("alpha"));
2339 vcard_n_prettyize(addrbook[i].ab_name);
2340 escputs(addrbook[i].ab_name);
2341 wprintf("</a></td>\n");
2345 /* Placeholders for empty columns at end */
2346 if ((num_ab % 4) != 0) {
2347 for (i=0; i<(4-(num_ab % 4)); ++i) {
2348 wprintf("<td> </td>");
2352 wprintf("</tr></table>\n");
2353 end_tab((num_pages-1), num_pages);
2355 begin_tab(num_pages, num_pages);
2356 /* FIXME there ought to be something here */
2357 end_tab(num_pages, num_pages);
2359 for (i=0; i<num_pages; ++i) {
2368 * load message pointers from the server for a "read messages" operation
2370 * servcmd: the citadel command to send to the citserver
2371 * with_headers: also include some of the headers with the message numbers (more expensive)
2373 int load_msg_ptrs(char *servcmd, int with_headers)
2375 StrBuf* FoundCharset = NULL;
2376 struct wcsession *WCC = WC;
2377 message_summary *Msg;
2380 ///time_t datestamp;
2381 //char fullname[128];
2382 //char nodename[128];
2383 //char inetaddr[128];
2384 //char subject[1024];
2391 ////int num_summ_alloc = 0;
2393 if (WCC->summ != NULL) {
2394 if (WCC->summ != NULL)
2395 DeleteHash(&WCC->summ);
2397 WCC->summ = NewHash(1, Flathash);
2399 maxload = 1000;/// TODO
2403 StrBuf_ServGetln(Buf);
2404 if (GetServerStatus(Buf, NULL) != 1) {
2408 // TODO if (with_headers) { //// TODO: Have Attachments?
2410 while (len = StrBuf_ServGetln(Buf),
2412 strcmp(ChrPtr(Buf), "000")!= 0))
2414 if (nummsgs < maxload) {
2415 Msg = (message_summary*)malloc(sizeof(message_summary));
2416 memset(Msg, 0, sizeof(message_summary));
2418 Msg->msgnum = StrBufExtract_long(Buf, 0, '|');
2419 Msg->date = StrBufExtract_long(Buf, 1, '|');
2421 Msg->from = NewStrBufPlain(NULL, StrLength(Buf));
2422 StrBufExtract_token(Buf2, Buf, 2, '|');
2423 if (StrLength(Buf2) != 0) {
2424 /** Handle senders with RFC2047 encoding */
2425 StrBuf_RFC822_to_Utf8(Msg->from, Buf2, WCC->DefaultCharset, FoundCharset);
2429 StrBufExtract_token(Buf2, Buf, 3, '|');
2430 if ((StrLength(Buf2) !=0 ) &&
2431 ( ((WCC->room_flags & QR_NETWORK)
2432 || ((strcasecmp(ChrPtr(Buf2), serv_info.serv_nodename)
2433 && (strcasecmp(ChrPtr(Buf2), serv_info.serv_fqdn)))))))
2435 StrBufAppendBufPlain(Msg->from, HKEY(" @ "), 0);
2436 StrBufAppendBuf(Msg->from, Buf2, 0);
2440 StrBufExtract_token(Msg->inetaddr, Buf, 4, '|');
2443 Msg->subj = NewStrBufPlain(NULL, StrLength(Buf));
2444 StrBufExtract_token(Buf2, Buf, 5, '|');
2445 if (StrLength(Buf2) == 0)
2446 StrBufAppendBufPlain(Msg->subj, _("(no subj)"), 0, -1);
2448 StrBuf_RFC822_to_Utf8(Msg->subj, Buf2, WCC->DefaultCharset, FoundCharset);
2449 if ((StrLength(Msg->subj) > 75) &&
2450 (StrBuf_Utf8StrLen(Msg->subj) > 75)) {
2451 StrBuf_Utf8StrCut(Msg->subj, 72);
2452 StrBufAppendBufPlain(Msg->subj, HKEY("..."), 0);
2457 if ((StrLength(Msg->from) > 25) &&
2458 (StrBuf_Utf8StrLen(Msg->from) > 25)) {
2459 StrBuf_Utf8StrCut(Msg->from, 23);
2460 StrBufAppendBufPlain(Msg->from, HKEY("..."), 0);
2462 Put(WCC->summ, (const char*)&Msg->msgnum, sizeof(Msg->msgnum), Msg, DestroyMessageSummary);
2477 * command loop for reading messages
2479 * Set oper to "readnew" or "readold" or "readfwd" or "headers"
2481 void readloop(char *oper)
2484 message_summary *Msg;
2493 long *displayed_msgs = NULL;
2494 int num_displayed = 0;
2496 int is_addressbook = 0;
2497 int is_singlecard = 0;
2498 int is_calendar = 0;
2499 struct calview calv;
2504 int lowest_displayed = (-1);
2505 int highest_displayed = 0;
2506 struct addrbookent *addrbook = NULL;
2508 const StrBuf *sortby = NULL;
2510 int SortBy = eRDate;
2511 const StrBuf *sortpref_value;
2512 int bbs_reverse = 0;
2513 struct wcsession *WCC = WC; /* This is done to make it run faster; WC is a function */
2515 const char *HashKey;
2518 if (WCC->wc_view == VIEW_WIKI) {
2519 sprintf(buf, "wiki?room=%s&page=home", WCC->wc_roomname);
2524 startmsg = lbstr("startmsg");
2525 maxmsgs = ibstr("maxmsgs");
2526 is_summary = (ibstr("is_summary") && !WCC->is_mobile);
2527 if (maxmsgs == 0) maxmsgs = DEFAULT_MAXMSGS;
2529 sortpref_value = get_room_pref("sort");
2531 sortby = sbstr("sortby");
2532 if ( (!IsEmptyStr(ChrPtr(sortby))) &&
2533 (strcasecmp(ChrPtr(sortby), ChrPtr(sortpref_value)) != 0)) {
2534 set_room_pref("sort", NewStrBufDup(sortby), 1);
2535 sortpref_value = NULL;
2536 sortpref_value = sortby;
2539 SortBy = StrToESort(sortpref_value);
2540 /* message board sort */
2541 if (SortBy == eReverse) {
2548 output_headers(1, 1, 1, 0, 0, 0);
2551 * When in summary mode, always show ALL messages instead of just
2552 * new or old. Otherwise, show what the user asked for.
2554 if (!strcmp(oper, "readnew")) {
2555 strcpy(cmd, "MSGS NEW");
2557 else if (!strcmp(oper, "readold")) {
2558 strcpy(cmd, "MSGS OLD");
2560 else if (!strcmp(oper, "do_search")) {
2561 snprintf(cmd, sizeof(cmd), "MSGS SEARCH|%s", bstr("query"));
2564 strcpy(cmd, "MSGS ALL");
2567 if ((WCC->wc_view == VIEW_MAILBOX) && (maxmsgs > 1) && !WCC->is_mobile) {
2569 if (!strcmp(oper, "do_search")) {
2570 snprintf(cmd, sizeof(cmd), "MSGS SEARCH|%s", bstr("query"));
2573 strcpy(cmd, "MSGS ALL");
2577 if ((WCC->wc_view == VIEW_ADDRESSBOOK) && (maxmsgs > 1)) {
2579 if (!strcmp(oper, "do_search")) {
2580 snprintf(cmd, sizeof(cmd), "MSGS SEARCH|%s", bstr("query"));
2583 strcpy(cmd, "MSGS ALL");
2588 if (is_summary) { /**< fetch header summary */
2589 snprintf(cmd, sizeof(cmd), "MSGS %s|%s||1",
2590 (!strcmp(oper, "do_search") ? "SEARCH" : "ALL"),
2591 (!strcmp(oper, "do_search") ? bstr("query") : "")
2596 if (WCC->is_mobile) {
2598 snprintf(cmd, sizeof(cmd), "MSGS %s|%s||1",
2599 (!strcmp(oper, "do_search") ? "SEARCH" : "ALL"),
2600 (!strcmp(oper, "do_search") ? bstr("query") : "")
2606 * Are we doing a summary view? If so, we need to know old messages
2607 * and new messages, so we can do that pretty boldface thing for the
2610 strcpy(old_msgs, "");
2611 if ((is_summary) || (WCC->wc_default_view == VIEW_CALENDAR) || WCC->is_mobile){
2613 serv_getln(buf, sizeof buf);
2614 if (buf[0] == '2') {
2615 strcpy(old_msgs, &buf[4]);
2619 is_singlecard = ibstr("is_singlecard");
2621 if (WCC->wc_default_view == VIEW_CALENDAR) { /**< calendar */
2623 strcpy(cmd, "MSGS ALL|||1");
2625 parse_calendar_view_request(&calv);
2627 if (WCC->wc_default_view == VIEW_TASKS) { /**< tasks */
2629 strcpy(cmd, "MSGS ALL");
2632 if (WCC->wc_default_view == VIEW_NOTES) { /**< notes */
2634 strcpy(cmd, "MSGS ALL");
2639 wprintf("<div id=\"new_notes_here\"></div>\n");
2642 nummsgs = load_msg_ptrs(cmd, (is_summary || WCC->is_mobile));
2645 if ((!is_tasks) && (!is_calendar) && (!is_notes) && (!is_addressbook)) {
2646 wprintf("<div align=\"center\"><br /><em>");
2647 if (!strcmp(oper, "readnew")) {
2648 wprintf(_("No new messages."));
2649 } else if (!strcmp(oper, "readold")) {
2650 wprintf(_("No old messages."));
2652 wprintf(_("No messages here."));
2654 wprintf("</em><br /></div>\n");
2660 if ((is_summary) || (WCC->wc_default_view == VIEW_CALENDAR) || WCC->is_mobile){
2662 message_summary *Msg;
2664 at = GetNewHashPos();
2665 while (GetNextHashPos(WCC->summ, at, &HKLen, &HashKey, &vMsg)) {
2666 /** Are you a new message, or an old message? */
2667 Msg = (message_summary*) vMsg;
2669 if (is_msg_in_mset(old_msgs, Msg->msgnum)) {
2680 if (startmsg == 0L) {
2682 startmsg = WCC->msgarr[(nummsgs >= maxmsgs) ? (nummsgs - maxmsgs) : 0];
2685 startmsg = WCC->msgarr[0];
2689 if (is_summary || WCC->is_mobile) {
2690 SortByPayload(WCC->summ, SortFuncs[SortBy]);
2695 wprintf("<script language=\"javascript\" type=\"text/javascript\">"
2696 " document.onkeydown = CtdlMsgListKeyPress; "
2697 " if (document.layers) { "
2698 " document.captureEvents(Event.KEYPRESS); "
2703 /** note that Date and Delete are now in the same column */
2704 wprintf("<div id=\"message_list_hdr\">"
2705 "<div class=\"fix_scrollbar_bug\">"
2706 "<table cellspacing=0 style=\"width:100%%\">"
2709 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"
2710 "<th width=%d%%>%s <a href=\"readfwd?startmsg=1?maxmsgs=9999999?is_summary=1?sortby=%s\"><img border=\"0\" src=\"%s\" /></a> </th>\n"
2711 "<th width=%d%%>%s <a href=\"readfwd?startmsg=1?maxmsgs=9999999?is_summary=1?sortby=%s\"><img border=\"0\" src=\"%s\" /></a> \n"
2713 "<input type=\"submit\" name=\"delete_button\" id=\"delbutton\" "
2714 " onClick=\"CtdlDeleteSelectedMessages(event)\" "
2721 SortByStrings[SubjectInvertSortString[SortBy]],
2722 SortIcons[SortSubjectToIcon[SortBy]],
2723 SENDER_COL_WIDTH_PCT,
2725 SortByStrings[SenderInvertSortString[SortBy]],
2726 SortIcons[SortSenderToIcon[SortBy]],
2727 DATE_PLUS_BUTTONS_WIDTH_PCT,
2729 SortByStrings[DateInvertSortString[SortBy]],
2730 SortIcons[SortDateToIcon[SortBy]],
2733 wprintf("</table></div></div>\n");
2734 wprintf("<div id=\"message_list\">"
2736 "<div class=\"fix_scrollbar_bug\">\n"
2737 "<table class=\"mailbox_summary\" id=\"summary_headers\" "
2738 "cellspacing=0 style=\"width:100%%;-moz-user-select:none;\">"
2740 } else if (WCC->is_mobile) {
2741 wprintf("<div id=\"message_list\">");
2746 * Set the "is_bbview" variable if it appears that we are looking at
2747 * a classic bulletin board view.
2749 if ((!is_tasks) && (!is_calendar) && (!is_addressbook)
2750 && (!is_notes) && (!is_singlecard) && (!is_summary)) {
2755 * If we're not currently looking at ALL requested
2756 * messages, then display the selector bar
2759 /** begin bbview scroller */
2760 wprintf("<form name=\"msgomatictop\" class=\"selector_top\" > \n <p>");
2761 wprintf(_("Reading #"));//// TODO this isn't used, should it? : , lowest_displayed, highest_displayed);
2763 wprintf("<select name=\"whichones\" size=\"1\" "
2764 "OnChange=\"location.href=msgomatictop.whichones.options"
2765 "[selectedIndex].value\">\n");
2768 for (b=nummsgs-1; b>=0; b = b - maxmsgs) {
2770 lo = b - maxmsgs + 2;
2772 wprintf("<option %s value="
2777 "%d-%d</option> \n",
2778 ((WCC->msgarr[lo-1] == startmsg) ? "selected" : ""),
2787 for (b=0; b<nummsgs; b = b + maxmsgs) {
2789 hi = b + maxmsgs + 1;
2790 if (hi > nummsgs) hi = nummsgs;
2791 wprintf("<option %s value="
2796 "%d-%d</option> \n",
2797 ((WCC->msgarr[b] == startmsg) ? "selected" : ""),
2806 wprintf("<option value=\"%s?startmsg=%ld"
2807 "&maxmsgs=9999999&is_summary=%d\">",
2809 WCC->msgarr[0], is_summary);
2811 wprintf("</option>");
2812 wprintf("</select> ");
2813 wprintf(_("of %d messages."), nummsgs);
2815 /** forward/reverse */
2816 wprintf("<input type=\"radio\" %s name=\"direction\" value=\"\""
2817 "OnChange=\"location.href='%s?sortby=forward'\"",
2818 (bbs_reverse ? "" : "checked"),
2822 wprintf(_("oldest to newest"));
2823 wprintf(" ");
2825 wprintf("<input type=\"radio\" %s name=\"direction\" value=\"\""
2826 "OnChange=\"location.href='%s?sortby=reverse'\"",
2827 (bbs_reverse ? "checked" : ""),
2831 wprintf(_("newest to oldest"));
2834 wprintf("</p></form>\n");
2835 /** end bbview scroller */
2838 at = GetNewHashPos();
2839 while (GetNextHashPos(WCC->summ, at, &HKLen, &HashKey, &vMsg)) {
2840 Msg = (message_summary*) vMsg;
2841 if ((Msg->msgnum >= startmsg) && (num_displayed < maxmsgs)) {
2843 /** Display the message */
2845 DoTemplate(HKEY("section_mailsummary"), NULL, Msg, CTX_MAILSUM);
2847 else if (is_addressbook) {
2848 fetch_ab_name(Msg, buf);
2850 addrbook = realloc(addrbook,
2851 (sizeof(struct addrbookent) * num_ab) );
2852 safestrncpy(addrbook[num_ab-1].ab_name, buf,
2853 sizeof(addrbook[num_ab-1].ab_name));
2854 addrbook[num_ab-1].ab_msgnum = Msg->msgnum;
2856 else if (is_calendar) {
2857 load_calendar_item(Msg, Msg->is_new, &calv);
2859 else if (is_tasks) {
2860 display_task(Msg, Msg->is_new);
2862 else if (is_notes) {
2863 display_note(Msg, Msg->is_new);
2864 } else if (WCC->is_mobile) {
2865 DoTemplate(HKEY("section_mailsummary"), NULL, Msg, CTX_MAILSUM);
2868 if (displayed_msgs == NULL) {
2869 displayed_msgs = malloc(sizeof(long) *
2870 (maxmsgs<nummsgs ? maxmsgs : nummsgs));
2872 displayed_msgs[num_displayed] = Msg->msgnum;
2875 if (lowest_displayed < 0) lowest_displayed = a;
2876 highest_displayed = a;
2884 if (displayed_msgs != NULL) {
2886 qsort(displayed_msgs, num_displayed, sizeof(long), longcmp_r);
2889 /** if we do a split bbview in the future, begin messages div here */
2891 for (a=0; a<num_displayed; ++a) {
2892 read_message(displayed_msgs[a], 0, "");
2895 /** if we do a split bbview in the future, end messages div here */
2897 free(displayed_msgs);
2898 displayed_msgs = NULL;
2903 "</div>\n"); /**< end of 'fix_scrollbar_bug' div */
2904 wprintf("</div>"); /**< end of 'message_list' div */
2906 /** Here's the grab-it-to-resize-the-message-list widget */
2907 wprintf("<div id=\"resize_msglist\" "
2908 "onMouseDown=\"CtdlResizeMsgListMouseDown(event)\">"
2909 "<div class=\"fix_scrollbar_bug\"> <hr>"
2913 wprintf("<div id=\"preview_pane\">"); /**< The preview pane will initially be empty */
2914 } else if (WCC->is_mobile) {
2919 * Bump these because although we're thinking in zero base, the user
2920 * is a drooling idiot and is thinking in one base.
2923 ++highest_displayed;
2926 * If we're not currently looking at ALL requested
2927 * messages, then display the selector bar
2930 /** begin bbview scroller */
2931 wprintf("<form name=\"msgomatic\" class=\"selector_bottom\" > \n <p>");
2932 wprintf(_("Reading #")); /// TODO: this isn't used: , lowest_displayed, highest_displayed);
2934 wprintf("<select name=\"whichones\" size=\"1\" "
2935 "OnChange=\"location.href=msgomatic.whichones.options"
2936 "[selectedIndex].value\">\n");
2939 for (b=nummsgs-1; b>=0; b = b - maxmsgs) {
2941 lo = b - maxmsgs + 2;
2943 wprintf("<option %s value="
2948 "%d-%d</option> \n",
2949 ((WCC->msgarr[lo-1] == startmsg) ? "selected" : ""),
2958 for (b=0; b<nummsgs; b = b + maxmsgs) {
2960 hi = b + maxmsgs + 1;
2961 if (hi > nummsgs) hi = nummsgs;
2962 wprintf("<option %s value="
2967 "%d-%d</option> \n",
2968 ((WCC->msgarr[b] == startmsg) ? "selected" : ""),
2977 wprintf("<option value=\"%s&startmsg=%ld"
2978 "&maxmsgs=9999999&is_summary=%d\">",
2980 WCC->msgarr[0], is_summary);
2982 wprintf("</option>");
2983 wprintf("</select> ");
2984 wprintf(_("of %d messages."), nummsgs);
2986 /** forward/reverse */
2987 wprintf("<input type=\"radio\" %s name=\"direction\" value=\"\""
2988 "OnChange=\"location.href='%s&sortby=forward'\"",
2989 (bbs_reverse ? "" : "checked"),
2993 wprintf(_("oldest to newest"));
2994 wprintf(" ");
2995 wprintf("<input type=\"radio\" %s name=\"direction\" value=\"\""
2996 "OnChange=\"location.href='%s&sortby=reverse'\"",
2997 (bbs_reverse ? "checked" : ""),
3001 wprintf(_("newest to oldest"));
3004 wprintf("</p></form>\n");
3005 /** end bbview scroller */
3010 do_tasks_view(); /** Render the task list */
3014 render_calendar_view(&calv);
3017 if (is_addressbook) {
3018 do_addrbook_view(addrbook, num_ab); /** Render the address book */
3021 /** Note: wDumpContent() will output one additional </div> tag. */
3022 wprintf("</div>\n"); /** end of 'content' div */
3025 /** free the summary */
3026 if (WCC->summ != NULL) {
3027 DeleteHash(&WCC->summ);
3029 if (addrbook != NULL) free(addrbook);
3034 * Back end for post_message()
3035 * ... this is where the actual message gets transmitted to the server.
3037 void post_mime_to_server(void) {
3038 char top_boundary[SIZ];
3039 char alt_boundary[SIZ];
3040 int is_multipart = 0;
3042 struct wc_attachment *att;
3044 size_t encoded_length;
3045 size_t encoded_strlen;
3046 char *txtmail = NULL;
3048 sprintf(top_boundary, "Citadel--Multipart--%s--%04x--%04x",
3049 serv_info.serv_fqdn,
3053 sprintf(alt_boundary, "Citadel--Multipart--%s--%04x--%04x",
3054 serv_info.serv_fqdn,
3059 /* RFC2045 requires this, and some clients look for it... */
3060 serv_puts("MIME-Version: 1.0");
3061 serv_puts("X-Mailer: " PACKAGE_STRING);
3063 /* If there are attachments, we have to do multipart/mixed */
3064 if (WC->first_attachment != NULL) {
3069 /* Remember, serv_printf() appends an extra newline */
3070 serv_printf("Content-type: multipart/mixed; boundary=\"%s\"\n", top_boundary);
3071 serv_printf("This is a multipart message in MIME format.\n");
3072 serv_printf("--%s", top_boundary);
3075 /* Remember, serv_printf() appends an extra newline */
3076 serv_printf("Content-type: multipart/alternative; "
3077 "boundary=\"%s\"\n", alt_boundary);
3078 serv_printf("This is a multipart message in MIME format.\n");
3079 serv_printf("--%s", alt_boundary);
3081 serv_puts("Content-type: text/plain; charset=utf-8");
3082 serv_puts("Content-Transfer-Encoding: quoted-printable");
3084 txtmail = html_to_ascii(bstr("msgtext"), 0, 80, 0);
3085 text_to_server_qp(txtmail); /* Transmit message in quoted-printable encoding */
3088 serv_printf("--%s", alt_boundary);
3090 serv_puts("Content-type: text/html; charset=utf-8");
3091 serv_puts("Content-Transfer-Encoding: quoted-printable");
3093 serv_puts("<html><body>\r\n");
3094 text_to_server_qp(bstr("msgtext")); /* Transmit message in quoted-printable encoding */
3095 serv_puts("</body></html>\r\n");
3097 serv_printf("--%s--", alt_boundary);
3101 /* Add in the attachments */
3102 for (att = WC->first_attachment; att!=NULL; att=att->next) {
3104 encoded_length = ((att->length * 150) / 100);
3105 encoded = malloc(encoded_length);
3106 if (encoded == NULL) break;
3107 encoded_strlen = CtdlEncodeBase64(encoded, att->data, att->length, 1);
3109 serv_printf("--%s", top_boundary);
3110 serv_printf("Content-type: %s", att->content_type);
3111 serv_printf("Content-disposition: attachment; filename=\"%s\"", att->filename);
3112 serv_puts("Content-transfer-encoding: base64");
3114 serv_write(encoded, encoded_strlen);
3119 serv_printf("--%s--", top_boundary);
3127 * Post message (or don't post message)
3129 * Note regarding the "dont_post" variable:
3130 * A random value (actually, it's just a timestamp) is inserted as a hidden
3131 * field called "postseq" when the display_enter page is generated. This
3132 * value is checked when posting, using the static variable dont_post. If a
3133 * user attempts to post twice using the same dont_post value, the message is
3134 * discarded. This prevents the accidental double-saving of the same message
3135 * if the user happens to click the browser "back" button.
3137 void post_message(void)
3140 StrBuf *encoded_subject = NULL;
3141 static long dont_post = (-1L);
3142 struct wc_attachment *att, *aptr;
3143 int is_anonymous = 0;
3144 const StrBuf *display_name = NULL;
3145 struct wcsession *WCC = WC;
3147 if (havebstr("force_room")) {
3148 gotoroom(bstr("force_room"));
3151 if (havebstr("display_name")) {
3152 display_name = sbstr("display_name");
3153 if (!strcmp(ChrPtr(display_name), "__ANONYMOUS__")) {
3154 display_name = NULL;
3159 if (WCC->upload_length > 0) {
3161 lprintf(9, "%s:%d: we are uploading %d bytes\n", __FILE__, __LINE__, WCC->upload_length);
3162 /** There's an attachment. Save it to this struct... */
3163 att = malloc(sizeof(struct wc_attachment));
3164 memset(att, 0, sizeof(struct wc_attachment));
3165 att->length = WCC->upload_length;
3166 strcpy(att->content_type, WCC->upload_content_type);
3167 strcpy(att->filename, WCC->upload_filename);
3170 /** And add it to the list. */
3171 if (WCC->first_attachment == NULL) {
3172 WCC->first_attachment = att;
3175 aptr = WCC->first_attachment;
3176 while (aptr->next != NULL) aptr = aptr->next;
3181 * Mozilla sends a simple filename, which is what we want,
3182 * but Satan's Browser sends an entire pathname. Reduce
3183 * the path to just a filename if we need to.
3185 while (num_tokens(att->filename, '/') > 1) {
3186 remove_token(att->filename, 0, '/');
3188 while (num_tokens(att->filename, '\\') > 1) {
3189 remove_token(att->filename, 0, '\\');
3193 * Transfer control of this memory from the upload struct
3194 * to the attachment struct.
3196 att->data = WCC->upload;
3197 WCC->upload_length = 0;
3203 if (havebstr("cancel_button")) {
3204 sprintf(WCC->ImportantMessage,
3205 _("Cancelled. Message was not posted."));
3206 } else if (havebstr("attach_button")) {
3209 } else if (lbstr("postseq") == dont_post) {
3210 sprintf(WCC->ImportantMessage,
3211 _("Automatically cancelled because you have already "
3212 "saved this message."));
3214 const char CMD[] = "ENT0 1|%s|%d|4|%s|%s||%s|%s|%s|%s|%s";
3215 const StrBuf *Recp = NULL;
3216 const StrBuf *Cc = NULL;
3217 const StrBuf *Bcc = NULL;
3218 const StrBuf *Wikipage = NULL;
3219 const StrBuf *my_email_addr = NULL;
3220 StrBuf *CmdBuf = NULL;;
3221 StrBuf *references = NULL;
3223 if (havebstr("references"))
3225 const StrBuf *ref = sbstr("references");
3226 references = NewStrBufPlain(ChrPtr(ref), StrLength(ref));
3227 lprintf(9, "Converting: %s\n", ChrPtr(references));
3228 StrBufReplaceChars(references, '|', '!');
3229 lprintf(9, "Converted: %s\n", ChrPtr(references));
3231 if (havebstr("subject")) {
3234 * make enough room for the encoded string;
3235 * plus the QP header
3237 Subj = sbstr("subject");
3239 StrBufRFC2047encode(&encoded_subject, Subj);
3241 Recp = sbstr("recp");
3244 Wikipage = sbstr("wikipage");
3245 my_email_addr = sbstr("my_email_addr");
3247 CmdBuf = NewStrBufPlain(NULL,
3250 StrLength(encoded_subject) +
3253 StrLength(Wikipage) +
3254 StrLength(my_email_addr) +
3255 StrLength(references));
3257 StrBufPrintf(CmdBuf,
3261 ChrPtr(encoded_subject),
3262 ChrPtr(display_name),
3266 ChrPtr(my_email_addr),
3267 ChrPtr(references));
3268 FreeStrBuf(&references);
3270 lprintf(9, "%s\n", CmdBuf);
3271 serv_puts(ChrPtr(CmdBuf));
3272 serv_getln(buf, sizeof buf);
3273 FreeStrBuf(&CmdBuf);
3274 FreeStrBuf(&encoded_subject);
3275 if (buf[0] == '4') {
3276 post_mime_to_server();
3277 if ( (havebstr("recp"))
3278 || (havebstr("cc" ))
3279 || (havebstr("bcc" ))
3281 sprintf(WCC->ImportantMessage, _("Message has been sent.\n"));
3284 sprintf(WC->ImportantMessage, _("Message has been posted.\n"));
3286 dont_post = lbstr("postseq");
3288 lprintf(9, "%s:%d: server post error: %s\n", __FILE__, __LINE__, buf);
3289 sprintf(WC->ImportantMessage, "%s", &buf[4]);
3295 free_attachments(WCC);
3298 * We may have been supplied with instructions regarding the location
3299 * to which we must return after posting. If found, go there.
3301 if (havebstr("return_to")) {
3302 http_redirect(bstr("return_to"));
3305 * If we were editing a page in a wiki room, go to that page now.
3307 else if (havebstr("wikipage")) {
3308 snprintf(buf, sizeof buf, "wiki?page=%s", bstr("wikipage"));
3312 * Otherwise, just go to the "read messages" loop.
3315 readloop("readnew");
3323 * \brief display the message entry screen
3325 void display_enter(void)
3330 const StrBuf *display_name = NULL;
3331 struct wc_attachment *att;
3332 int recipient_required = 0;
3333 int subject_required = 0;
3334 int recipient_bad = 0;
3335 int is_anonymous = 0;
3336 long existing_page = (-1L);
3337 struct wcsession *WCC = WC;
3341 if (havebstr("force_room")) {
3342 gotoroom(bstr("force_room"));
3345 display_name = sbstr("display_name");
3346 if (!strcmp(ChrPtr(display_name), "__ANONYMOUS__")) {
3347 display_name = NULL;
3351 /** First test to see whether this is a room that requires recipients to be entered */
3352 serv_puts("ENT0 0");
3353 serv_getln(buf, sizeof buf);
3355 if (!strncmp(buf, "570", 3)) { /** 570 means that we need a recipient here */
3356 recipient_required = 1;
3358 else if (buf[0] != '2') { /** Any other error means that we cannot continue */
3359 sprintf(WCC->ImportantMessage, "%s", &buf[4]);
3360 readloop("readnew");
3364 /* Is the server strongly recommending that the user enter a message subject? */
3365 if ((buf[3] != '\0') && (buf[4] != '\0')) {
3366 subject_required = extract_int(&buf[4], 1);
3370 * Are we perhaps in an address book view? If so, then an "enter
3371 * message" command really means "add new entry."
3373 if (WCC->wc_default_view == VIEW_ADDRESSBOOK) {
3374 do_edit_vcard(-1, "", "", WCC->wc_roomname);
3379 * Are we perhaps in a calendar room? If so, then an "enter
3380 * message" command really means "add new calendar item."
3382 if (WCC->wc_default_view == VIEW_CALENDAR) {
3383 display_edit_event();
3388 * Are we perhaps in a tasks view? If so, then an "enter
3389 * message" command really means "add new task."
3391 if (WCC->wc_default_view == VIEW_TASKS) {
3392 display_edit_task();
3397 * Otherwise proceed normally.
3398 * Do a custom room banner with no navbar...
3400 output_headers(1, 1, 2, 0, 0, 0);
3401 wprintf("<div id=\"banner\">\n");
3402 embed_room_banner(NULL, navbar_none);
3403 wprintf("</div>\n");
3404 wprintf("<div id=\"content\">\n"
3405 "<div class=\"fix_scrollbar_bug message \">");
3407 /* Now check our actual recipients if there are any */
3408 if (recipient_required) {
3409 const StrBuf *Recp = NULL;
3410 const StrBuf *Cc = NULL;
3411 const StrBuf *Bcc = NULL;
3412 const StrBuf *Wikipage = NULL;
3413 StrBuf *CmdBuf = NULL;;
3414 const char CMD[] = "ENT0 0|%s|%d|0||%s||%s|%s|%s";
3416 Recp = sbstr("recp");
3419 Wikipage = sbstr("wikipage");
3421 CmdBuf = NewStrBufPlain(NULL,
3424 StrLength(display_name) +
3427 StrLength(Wikipage));
3429 StrBufPrintf(CmdBuf,
3433 ChrPtr(display_name),
3437 serv_puts(ChrPtr(CmdBuf));
3438 serv_getln(buf, sizeof buf);
3439 FreeStrBuf(&CmdBuf);
3441 if (!strncmp(buf, "570", 3)) { /** 570 means we have an invalid recipient listed */
3442 if (havebstr("recp") &&
3448 else if (buf[0] != '2') { /** Any other error means that we cannot continue */
3449 wprintf("<em>%s</em><br />\n", &buf[4]);
3454 /** If we got this far, we can display the message entry screen. */
3456 /* begin message entry screen */
3458 "enctype=\"multipart/form-data\" "
3460 "accept-charset=\"UTF-8\" "
3462 "name=\"enterform\""
3464 wprintf("<input type=\"hidden\" name=\"postseq\" value=\"%ld\">\n", now);
3465 if (WCC->wc_view == VIEW_WIKI) {
3466 wprintf("<input type=\"hidden\" name=\"wikipage\" value=\"%s\">\n", bstr("wikipage"));
3468 wprintf("<input type=\"hidden\" name=\"return_to\" value=\"%s\">\n", bstr("return_to"));
3469 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WCC->nonce);
3470 wprintf("<input type=\"hidden\" name=\"force_room\" value=\"");
3471 escputs(WCC->wc_roomname);
3473 wprintf("<input type=\"hidden\" name=\"references\" value=\"");
3474 escputs(bstr("references"));
3477 /** submit or cancel buttons */
3478 wprintf("<p class=\"send_edit_msg\">");
3479 wprintf("<input type=\"submit\" name=\"send_button\" value=\"");
3480 if (recipient_required) {
3481 wprintf(_("Send message"));
3483 wprintf(_("Post message"));
3486 "<input type=\"submit\" name=\"cancel_button\" value=\"%s\">\n", _("Cancel"));
3491 wprintf("<img src=\"static/newmess3_24x.gif\" class=\"imgedit\">");
3492 wprintf(" "); /** header bar */
3493 webcit_fmt_date(buf, now, 0);
3495 wprintf("\n"); /** header bar */
3497 wprintf("<table width=\"100%%\" class=\"edit_msg_table\">");
3499 wprintf("<th><label for=\"from_id\" > ");
3500 wprintf(_(" <I>from</I> "));
3501 wprintf("</label></th>");
3503 wprintf("<td colspan=\"2\">");
3505 /* Allow the user to select any of his valid screen names */
3507 wprintf("<select name=\"display_name\" size=1 id=\"from_id\">\n");
3510 serv_getln(buf, sizeof buf);
3511 if (buf[0] == '1') {
3512 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
3513 wprintf("<option %s value=\"",
3514 ((!strcasecmp(bstr("display_name"), buf)) ? "selected" : "")
3519 wprintf("</option>\n");
3523 if (WCC->room_flags & QR_ANONOPT) {
3524 wprintf("<option %s value=\"__ANONYMOUS__\">%s</option>\n",
3525 ((!strcasecmp(bstr("__ANONYMOUS__"), WCC->wc_fullname)) ? "selected" : ""),
3530 wprintf("</select>\n");
3532 /* If this is an email (not a post), allow the user to select any of his
3533 * valid email addresses.
3535 if (recipient_required) {
3537 serv_getln(buf, sizeof buf);
3538 if (buf[0] == '1') {
3539 wprintf("<select name=\"my_email_addr\" size=1>\n");
3540 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
3541 wprintf("<option value=\"");
3545 wprintf("></option>\n");
3547 wprintf("</select>\n");
3551 wprintf(_(" <I>in</I> "));
3552 escputs(WCC->wc_roomname);
3554 wprintf("</td></tr>");
3556 if (recipient_required) {
3560 wprintf("<tr><th><label for=\"recp_id\"> ");
3562 wprintf("</label></th>"
3563 "<td><input autocomplete=\"off\" type=\"text\" name=\"recp\" id=\"recp_id\" value=\"");
3564 ccraw = xbstr("recp", &len);
3565 copy = (char*) malloc(len * 2 + 1);
3566 memcpy(copy, ccraw, len + 1);
3567 utf8ify_rfc822_string(copy);
3570 wprintf("\" size=45 maxlength=1000 />");
3571 wprintf("<div class=\"auto_complete\" id=\"recp_name_choices\"></div>");
3572 wprintf("</td><td rowspan=\"3\" align=\"left\" valign=\"top\">");
3574 /** Pop open an address book -- begin **/
3576 "<a href=\"javascript:PopOpenAddressBook('recp_id|%s|cc_id|%s|bcc_id|%s');\" "
3578 "<img align=middle border=0 width=24 height=24 src=\"static/viewcontacts_24x.gif\">"
3580 _("To:"), _("CC:"), _("BCC:"),
3581 _("Contacts"), _("Contacts")
3583 /** Pop open an address book -- end **/
3585 wprintf("</td></tr>");
3587 wprintf("<tr><th><label for=\"cc_id\"> ");
3589 wprintf("</label></th>"
3590 "<td><input autocomplete=\"off\" type=\"text\" name=\"cc\" id=\"cc_id\" value=\"");
3591 ccraw = xbstr("cc", &len);
3592 copy = (char*) malloc(len * 2 + 1);
3593 memcpy(copy, ccraw, len + 1);
3594 utf8ify_rfc822_string(copy);
3597 wprintf("\" size=45 maxlength=1000 />");
3598 wprintf("<div class=\"auto_complete\" id=\"cc_name_choices\"></div>");
3599 wprintf("</td></tr>");
3601 wprintf("<tr><th><label for=\"bcc_id\"> ");
3603 wprintf("</label></th>"
3604 "<td><input autocomplete=\"off\" type=\"text\" name=\"bcc\" id=\"bcc_id\" value=\"");
3605 ccraw = xbstr("bcc", &len);
3606 copy = (char*) malloc(len * 2 + 1);
3607 memcpy(copy, ccraw, len + 1);
3608 utf8ify_rfc822_string(copy);
3611 wprintf("\" size=45 maxlength=1000 />");
3612 wprintf("<div class=\"auto_complete\" id=\"bcc_name_choices\"></div>");
3613 wprintf("</td></tr>");
3615 /** Initialize the autocomplete ajax helpers (found in wclib.js) */
3616 wprintf("<script type=\"text/javascript\"> \n"
3617 " activate_entmsg_autocompleters(); \n"
3623 wprintf("<tr><th><label for=\"subject_id\" > ");
3624 if (recipient_required || subject_required) {
3625 wprintf(_("Subject:"));
3628 wprintf(_("Subject (optional):"));
3630 wprintf("</label></th>"
3631 "<td colspan=\"2\">"
3632 "<input type=\"text\" name=\"subject\" id=\"subject_id\" value=\"");
3633 escputs(bstr("subject"));
3634 wprintf("\" size=45 maxlength=70>\n");
3635 wprintf("</td></tr>");
3637 wprintf("<tr><td colspan=\"3\">\n");
3639 wprintf("<textarea name=\"msgtext\" cols=\"80\" rows=\"15\">");
3641 /** If we're continuing from a previous edit, put our partially-composed message back... */
3642 msgescputs(bstr("msgtext"));
3644 /* If we're forwarding a message, insert it here... */
3645 if (lbstr("fwdquote") > 0L) {
3646 wprintf("<br><div align=center><i>");
3647 wprintf(_("--- forwarded message ---"));
3648 wprintf("</i></div><br>");
3649 pullquote_message(lbstr("fwdquote"), 1, 1);
3652 /** If we're replying quoted, insert the quote here... */
3653 else if (lbstr("replyquote") > 0L) {
3656 pullquote_message(lbstr("replyquote"), 0, 1);
3657 wprintf("</blockquote><br>");
3660 /** If we're editing a wiki page, insert the existing page here... */
3661 else if (WCC->wc_view == VIEW_WIKI) {
3662 safestrncpy(buf, bstr("wikipage"), sizeof buf);
3663 str_wiki_index(buf);
3664 existing_page = locate_message_by_uid(buf);
3665 if (existing_page >= 0L) {
3666 pullquote_message(existing_page, 1, 0);
3670 /** Insert our signature if appropriate... */
3671 if ( (WCC->is_mailbox) && !yesbstr("sig_inserted") ) {
3673 get_pref_yesno("use_sig", &UseSig, 0);
3676 const char *sig, *esig;
3678 get_preference("signature", &ebuf);
3680 StrBufEUid_unescapize(Sig, ebuf);
3682 esig = sig + StrLength(Sig);
3683 wprintf("<br>--<br>");
3684 while (sig <= esig) {
3688 else if (*sig == '<') {
3691 else if (*sig == '>') {
3694 else if (*sig == '&') {
3697 else if (*sig == '\"') {
3700 else if (*sig == '\'') {
3703 else /* since we're utf 8, is this a good idea? if (isprint(*sig))*/ {
3704 wprintf("%c", *sig);
3712 wprintf("</textarea>\n");
3714 /** Make sure we only insert our signature once */
3715 /** We don't care if it was there or not before, it needs to be there now. */
3716 wprintf("<input type=\"hidden\" name=\"sig_inserted\" value=\"yes\">\n");
3719 * The following template embeds the TinyMCE richedit control, and automatically
3720 * transforms the textarea into a richedit textarea.
3722 do_template("richedit", NULL);
3724 /** Enumerate any attachments which are already in place... */
3725 wprintf("<div class=\"attachment buttons\"><img src=\"static/diskette_24x.gif\" class=\"imgedit\" > ");
3726 wprintf(_("Attachments:"));
3728 wprintf("<select name=\"which_attachment\" size=1>");
3729 for (att = WCC->first_attachment; att != NULL; att = att->next) {
3730 wprintf("<option value=\"");
3731 urlescputs(att->filename);
3733 escputs(att->filename);
3734 /* wprintf(" (%s, %d bytes)",att->content_type,att->length); */
3735 wprintf("</option>\n");
3737 wprintf("</select>");
3739 /** Now offer the ability to attach additional files... */
3740 wprintf(" ");
3741 wprintf(_("Attach file:"));
3742 wprintf(" <input name=\"attachfile\" class=\"attachfile\" "
3743 "size=16 type=\"file\">\n "
3744 "<input type=\"submit\" name=\"attach_button\" value=\"%s\">\n", _("Add"));
3745 wprintf("</div>"); /* End of "attachment buttons" div */
3748 wprintf("</td></tr></table>");
3750 wprintf("</form>\n");
3751 wprintf("</div>\n"); /* end of "fix_scrollbar_bug" div */
3753 /* NOTE: address_book_popup() will close the "content" div. Don't close it here. */
3754 DONE: address_book_popup();
3760 * \brief delete a message
3762 void delete_msg(void)
3767 msgid = lbstr("msgid");
3769 if (WC->wc_is_trash) { /** Delete from Trash is a real delete */
3770 serv_printf("DELE %ld", msgid);
3772 else { /** Otherwise move it to Trash */
3773 serv_printf("MOVE %ld|_TRASH_|0", msgid);
3776 serv_getln(buf, sizeof buf);
3777 sprintf(WC->ImportantMessage, "%s", &buf[4]);
3779 readloop("readnew");
3784 * \brief move a message to another folder
3791 msgid = lbstr("msgid");
3793 if (havebstr("move_button")) {
3794 sprintf(buf, "MOVE %ld|%s", msgid, bstr("target_room"));
3796 serv_getln(buf, sizeof buf);
3797 sprintf(WC->ImportantMessage, "%s", &buf[4]);
3799 sprintf(WC->ImportantMessage, (_("The message was not moved.")));
3802 readloop("readnew");
3810 * Confirm move of a message
3812 void confirm_move_msg(void)
3818 msgid = lbstr("msgid");
3821 output_headers(1, 1, 2, 0, 0, 0);
3822 wprintf("<div id=\"banner\">\n");
3824 wprintf(_("Confirm move of message"));
3826 wprintf("</div>\n");
3828 wprintf("<div id=\"content\" class=\"service\">\n");
3830 wprintf("<CENTER>");
3832 wprintf(_("Move this message to:"));
3833 wprintf("<br />\n");
3835 wprintf("<form METHOD=\"POST\" action=\"move_msg\">\n");
3836 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
3837 wprintf("<INPUT TYPE=\"hidden\" NAME=\"msgid\" VALUE=\"%s\">\n", bstr("msgid"));
3839 wprintf("<SELECT NAME=\"target_room\" SIZE=5>\n");
3841 serv_getln(buf, sizeof buf);
3842 if (buf[0] == '1') {
3843 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
3844 extract_token(targ, buf, 0, '|', sizeof targ);
3845 wprintf("<OPTION>");
3850 wprintf("</SELECT>\n");
3851 wprintf("<br />\n");
3853 wprintf("<INPUT TYPE=\"submit\" NAME=\"move_button\" VALUE=\"%s\">", _("Move"));
3855 wprintf("<INPUT TYPE=\"submit\" NAME=\"cancel_button\" VALUE=\"%s\">", _("Cancel"));
3856 wprintf("</form></CENTER>\n");
3858 wprintf("</CENTER>\n");
3862 void readnew(void) { readloop("readnew");}
3863 void readold(void) { readloop("readold");}
3864 void readfwd(void) { readloop("readfwd");}
3865 void headers(void) { readloop("headers");}
3866 void do_search(void) { readloop("do_search");}
3877 WebcitAddUrlHandler(HKEY("readnew"), readnew, 0);
3878 WebcitAddUrlHandler(HKEY("readold"), readold, 0);
3879 WebcitAddUrlHandler(HKEY("readfwd"), readfwd, 0);
3880 WebcitAddUrlHandler(HKEY("headers"), headers, 0);
3881 WebcitAddUrlHandler(HKEY("do_search"), do_search, 0);
3882 WebcitAddUrlHandler(HKEY("display_enter"), display_enter, 0);
3883 WebcitAddUrlHandler(HKEY("post"), post_message, 0);
3884 WebcitAddUrlHandler(HKEY("move_msg"), move_msg, 0);
3885 WebcitAddUrlHandler(HKEY("delete_msg"), delete_msg, 0);
3886 WebcitAddUrlHandler(HKEY("confirm_move_msg"), confirm_move_msg, 0);
3887 WebcitAddUrlHandler(HKEY("msg"), embed_message, NEED_URL|AJAX);
3888 WebcitAddUrlHandler(HKEY("printmsg"), print_message, NEED_URL);
3889 WebcitAddUrlHandler(HKEY("mobilemsg"), mobile_message_view, NEED_URL);
3890 WebcitAddUrlHandler(HKEY("msgheaders"), display_headers, NEED_URL);
3892 RegisterNamespace("MAIL:SUMM:DATESTR", 0, 0, tmplput_MAIL_SUMM_DATE_STR, CTX_MAILSUM);
3893 RegisterNamespace("MAIL:SUMM:DATENO", 0, 0, tmplput_MAIL_SUMM_DATE_NO, CTX_MAILSUM);
3894 RegisterNamespace("MAIL:SUMM:N", 0, 0, tmplput_MAIL_SUMM_N, CTX_MAILSUM);
3895 RegisterNamespace("MAIL:SUMM:FROM", 0, 2, tmplput_MAIL_SUMM_FROM, CTX_MAILSUM);
3896 RegisterNamespace("MAIL:SUMM:TO", 0, 2, tmplput_MAIL_SUMM_TO, CTX_MAILSUM);
3897 RegisterNamespace("MAIL:SUMM:SUBJECT", 0, 4, tmplput_MAIL_SUMM_SUBJECT, CTX_MAILSUM);
3898 RegisterNamespace("MAIL:SUMM:NATTACH", 0, 0, tmplput_MAIL_SUMM_NATTACH, CTX_MAILSUM);
3899 RegisterNamespace("MAIL:SUMM:CCCC", 0, 2, tmplput_MAIL_SUMM_CCCC, CTX_MAILSUM);
3900 RegisterNamespace("MAIL:SUMM:H_NODE", 0, 2, tmplput_MAIL_SUMM_H_NODE, CTX_MAILSUM);
3901 RegisterNamespace("MAIL:SUMM:ALLRCPT", 0, 2, tmplput_MAIL_SUMM_ALLRCPT, CTX_MAILSUM);
3902 RegisterNamespace("MAIL:SUMM:ORGROOM", 0, 2, tmplput_MAIL_SUMM_ORGROOM, CTX_MAILSUM);
3903 RegisterNamespace("MAIL:SUMM:RFCA", 0, 2, tmplput_MAIL_SUMM_RFCA, CTX_MAILSUM);
3904 RegisterNamespace("MAIL:SUMM:OTHERNODE", 2, 0, tmplput_MAIL_SUMM_OTHERNODE, CTX_MAILSUM);
3905 RegisterNamespace("MAIL:SUMM:REFIDS", 0, 0, tmplput_MAIL_SUMM_REFIDS, CTX_MAILSUM);
3906 RegisterNamespace("MAIL:SUMM:INREPLYTO", 0, 2, tmplput_MAIL_SUMM_INREPLYTO, CTX_MAILSUM);
3907 RegisterNamespace("MAIL:BODY", 0, 2, tmplput_MAIL_BODY, CTX_MAILSUM);
3910 RegisterConditional(HKEY("COND:MAIL:SUMM:UNREAD"), 0, Conditional_MAIL_SUMM_UNREAD, CTX_MAILSUM);
3911 RegisterConditional(HKEY("COND:MAIL:SUMM:H_NODE"), 0, Conditional_MAIL_SUMM_H_NODE, CTX_MAILSUM);
3912 RegisterConditional(HKEY("COND:MAIL:SUMM:OTHERNODE"), 0, Conditional_MAIL_SUMM_OTHERNODE, CTX_MAILSUM);
3915 RegisterIterator("MAIL:MIME:ATTACH", 0, NULL, iterate_get_mime_All,
3916 tmplput_MIME_ATTACH, NULL, CTX_MIME_ATACH, CTX_MAILSUM);
3917 RegisterIterator("MAIL:MIME:ATTACH:SUBMESSAGES", 0, NULL, iterate_get_mime_Submessages,
3918 tmplput_MIME_ATTACH, NULL, CTX_MIME_ATACH, CTX_MAILSUM);
3919 RegisterIterator("MAIL:MIME:ATTACH:LINKS", 0, NULL, iterate_get_mime_AttachLinks,
3920 tmplput_MIME_ATTACH, NULL, CTX_MIME_ATACH, CTX_MAILSUM);
3921 RegisterIterator("MAIL:MIME:ATTACH:ATT", 0, NULL, iterate_get_mime_Attachments,
3922 tmplput_MIME_ATTACH, NULL, CTX_MIME_ATACH, CTX_MAILSUM);
3924 RegisterMimeRenderer(HKEY("text/x-citadel-variformat"), render_MAIL_variformat);
3925 RegisterMimeRenderer(HKEY("text/plain"), render_MAIL_text_plain);
3926 RegisterMimeRenderer(HKEY("text"), render_MAIL_text_plain);
3927 RegisterMimeRenderer(HKEY("text/html"), render_MAIL_html);
3928 RegisterMimeRenderer(HKEY(""), render_MAIL_UNKNOWN);
3930 RegisterMsgHdr(HKEY("nhdr"), examine_nhdr, 0);
3931 RegisterMsgHdr(HKEY("type"), examine_type, 0);
3932 RegisterMsgHdr(HKEY("from"), examine_from, 0);
3933 RegisterMsgHdr(HKEY("subj"), examine_subj, 0);
3934 RegisterMsgHdr(HKEY("msgn"), examine_msgn, 0);
3935 RegisterMsgHdr(HKEY("wefw"), examine_wefw, 0);
3936 RegisterMsgHdr(HKEY("cccc"), examine_cccc, 0);
3937 RegisterMsgHdr(HKEY("hnod"), examine_hnod, 0);
3938 RegisterMsgHdr(HKEY("room"), examine_room, 0);
3939 RegisterMsgHdr(HKEY("rfca"), examine_rfca, 0);
3940 RegisterMsgHdr(HKEY("node"), examine_node, 0);
3941 RegisterMsgHdr(HKEY("rcpt"), examine_rcpt, 0);
3942 RegisterMsgHdr(HKEY("time"), examine_time, 0);
3943 RegisterMsgHdr(HKEY("part"), examine_mime_part, 0);
3944 RegisterMsgHdr(HKEY("text"), examine_text, 1);
3945 RegisterMsgHdr(HKEY("X-Citadel-MSG4-Partnum"), examine_msg4_partnum, 0);
3946 RegisterMsgHdr(HKEY("Content-type"), examine_content_type, 0);
3947 RegisterMsgHdr(HKEY("Content-length"), examine_content_lengh, 0);
3948 RegisterMsgHdr(HKEY("Content-transfer-encoding"), examine_content_encoding, 0);