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 */
22 void display_enter(void);
23 int longcmp_r(const void *s1, const void *s2);
24 int summcmp_subj(const void *s1, const void *s2);
25 int summcmp_rsubj(const void *s1, const void *s2);
26 int summcmp_sender(const void *s1, const void *s2);
27 int summcmp_rsender(const void *s1, const void *s2);
28 int summcmp_date(const void *s1, const void *s2);
29 int summcmp_rdate(const void *s1, const void *s2);
31 /*----------------------------------------------------------------------------*/
34 typedef void (*MsgPartEvaluatorFunc)(message_summary *Sum, StrBuf *Buf);
38 const char* SortIcons[3] = {
39 "static/up_pointer.gif",
40 "static/down_pointer.gif",
41 "static/sort_none.gif"
55 /* SortEnum to plain string representation */
56 static const char* SortByStrings[] = {
67 /* SortEnum to sort-Function Table */
68 const CompareFunc SortFuncs[eUnSet] = {
78 /* given a SortEnum, which icon should we choose? */
79 const int SortDateToIcon[eUnSet] = { eUp, eDown, eNone, eNone, eNone, eNone, eNone};
80 const int SortSubjectToIcon[eUnSet] = { eNone, eNone, eUp, eDown, eNone, eNone, eNone};
81 const int SortSenderToIcon[eUnSet] = { eNone, eNone, eNone, eNone, eUp, eDown, eNone};
83 /* given a SortEnum, which would be the "opposite" search option? */
84 const int DateInvertSortString[eUnSet] = { eRDate, eDate, eDate, eDate, eDate, eDate, eDate};
85 const int SubjectInvertSortString[eUnSet] = { eSubject, eSubject, eRSubject, eUnSet, eSubject, eSubject, eSubject};
86 const int SenderInvertSortString[eUnSet] = { eSender, eSender, eSender, eSender, eRSender, eUnSet, eSender};
90 /*----------------------------------------------------------------------------*/
93 * Translates sortoption String to its SortEnum representation
94 * returns the enum matching the string; defaults to RDate
97 int StrToESort (const StrBuf *sortby)
101 if (!IsEmptyStr(ChrPtr(sortby))) while (result < eUnSet){
102 if (!strcasecmp(ChrPtr(sortby),
103 SortByStrings[result]))
111 typedef int (*QSortFunction) (const void*, const void*);
114 * qsort() compatible function to compare two longs in descending order.
116 int longcmp_r(const void *s1, const void *s2) {
120 l1 = *(long *)GetSearchPayload(s1);
121 l2 = *(long *)GetSearchPayload(s2);
123 if (l1 > l2) return(-1);
124 if (l1 < l2) return(+1);
130 * qsort() compatible function to compare two message summary structs by ascending subject.
132 int summcmp_subj(const void *s1, const void *s2) {
133 message_summary *summ1;
134 message_summary *summ2;
136 summ1 = (message_summary *)GetSearchPayload(s1);
137 summ2 = (message_summary *)GetSearchPayload(s2);
138 return strcasecmp(ChrPtr(summ1->subj), ChrPtr(summ2->subj));
142 * qsort() compatible function to compare two message summary structs by descending subject.
144 int summcmp_rsubj(const void *s1, const void *s2) {
145 message_summary *summ1;
146 message_summary *summ2;
148 summ1 = (message_summary *)GetSearchPayload(s1);
149 summ2 = (message_summary *)GetSearchPayload(s2);
150 return strcasecmp(ChrPtr(summ2->subj), ChrPtr(summ1->subj));
154 * qsort() compatible function to compare two message summary structs by ascending sender.
156 int summcmp_sender(const void *s1, const void *s2) {
157 message_summary *summ1;
158 message_summary *summ2;
160 summ1 = (message_summary *)GetSearchPayload(s1);
161 summ2 = (message_summary *)GetSearchPayload(s2);
162 return strcasecmp(ChrPtr(summ1->from), ChrPtr(summ2->from));
166 * qsort() compatible function to compare two message summary structs by descending sender.
168 int summcmp_rsender(const void *s1, const void *s2) {
169 message_summary *summ1;
170 message_summary *summ2;
172 summ1 = (message_summary *)GetSearchPayload(s1);
173 summ2 = (message_summary *)GetSearchPayload(s2);
174 return strcasecmp(ChrPtr(summ2->from), ChrPtr(summ1->from));
178 * qsort() compatible function to compare two message summary structs by ascending date.
180 int summcmp_date(const void *s1, const void *s2) {
181 message_summary *summ1;
182 message_summary *summ2;
184 summ1 = (message_summary *)GetSearchPayload(s1);
185 summ2 = (message_summary *)GetSearchPayload(s2);
187 if (summ1->date < summ2->date) return -1;
188 else if (summ1->date > summ2->date) return +1;
193 * qsort() compatible function to compare two message summary structs by descending date.
195 int summcmp_rdate(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);
202 if (summ1->date < summ2->date) return +1;
203 else if (summ1->date > summ2->date) return -1;
214 * Look for URL's embedded in a buffer and make them linkable. We use a
215 * target window in order to keep the Citadel session in its own window.
217 void UrlizeText(StrBuf* Target, StrBuf *Source, StrBuf *WrkBuf)
219 int len, UrlLen, Offset, TrailerLen;
220 const char *start, *end, *pos;
225 len = StrLength(Source);
226 end = ChrPtr(Source) + len;
227 for (pos = ChrPtr(Source); (pos < end) && (start == NULL); ++pos) {
228 if (!strncasecmp(pos, "http://", 7))
230 if (!strncasecmp(pos, "ftp://", 6))
235 StrBufAppendBuf(Target, Source, 0);
240 for (pos = ChrPtr(Source) + len; pos > start; --pos) {
241 if ( (!isprint(*pos))
260 UrlLen = end - start;
261 StrBufAppendBufPlain(WrkBuf, start, UrlLen, 0);
263 Offset = start - ChrPtr(Source);
265 StrBufAppendBufPlain(Target, ChrPtr(Source), Offset, 0);
266 StrBufAppendPrintf(Target, "%ca href=%c%s%c TARGET=%c%s%c%c%s%c/A%c",
267 LB, QU, ChrPtr(WrkBuf), QU, QU, TARGET,
268 QU, RB, ChrPtr(WrkBuf), LB, RB);
270 TrailerLen = len - (end - start);
272 StrBufAppendBufPlain(Target, end, TrailerLen, 0);
274 void url(char *buf, size_t bufsize)
276 int len, UrlLen, Offset, TrailerLen, outpos;
277 char *start, *end, *pos;
284 lprintf(1, "URL: content longer than buffer!");
288 for (pos = buf; (pos < end) && (start == NULL); ++pos) {
289 if (!strncasecmp(pos, "http://", 7))
291 if (!strncasecmp(pos, "ftp://", 6))
298 for (pos = buf+len; pos > start; --pos) {
299 if ( (!isprint(*pos))
318 UrlLen = end - start;
319 if (UrlLen > sizeof(urlbuf)){
320 lprintf(1, "URL: content longer than buffer!");
323 memcpy(urlbuf, start, UrlLen);
324 urlbuf[UrlLen] = '\0';
326 Offset = start - buf;
327 if ((Offset != 0) && (Offset < sizeof(outbuf)))
328 memcpy(outbuf, buf, Offset);
329 outpos = snprintf(&outbuf[Offset], sizeof(outbuf) - Offset,
330 "%ca href=%c%s%c TARGET=%c%s%c%c%s%c/A%c",
331 LB, QU, urlbuf, QU, QU, TARGET, QU, RB, urlbuf, LB, RB);
332 if (outpos >= sizeof(outbuf) - Offset) {
333 lprintf(1, "URL: content longer than buffer!");
337 TrailerLen = len - (end - start);
339 memcpy(outbuf + Offset + outpos, end, TrailerLen);
340 if (Offset + outpos + TrailerLen > bufsize) {
341 lprintf(1, "URL: content longer than buffer!");
344 memcpy (buf, outbuf, Offset + outpos + TrailerLen);
345 *(buf + Offset + outpos + TrailerLen) = '\0';
359 * I wanna SEE that message!
361 * msgnum Message number to display
362 * printable_view Nonzero to display a printable view
363 * section Optional for encapsulated message/rfc822 submessage
365 void read_message(long msgnum, int printable_view, char *section) {
366 struct wcsession *WCC = WC;
369 StrBuf *FoundCharset;
370 message_summary *Msg = NULL;
374 struct attach_link *attach_links = NULL;
375 int num_attach_links = 0;
376 // char mime_submessages[256] = "";
377 char reply_references[1024] = "";
381 char vcard_partnum[256] = "";
382 char cal_partnum[256] = "";
383 char *part_source = NULL;
384 char msg4_partnum[32] = "";
386 //// strcpy(mime_submessages, "");
389 serv_printf("MSG4 %ld|%s", msgnum, section);
390 StrBuf_ServGetln(Buf);
391 if (GetServerStatus(Buf, NULL) != 1) {
393 wprintf(_("ERROR:"));
394 wprintf("</strong> %s<br />\n", &buf[4]);
398 svputlong("MsgPrintable", printable_view);
399 /** begin everythingamundo table */
403 Msg = (message_summary *)malloc(sizeof(message_summary));
404 memset(Msg, 0, sizeof(message_summary));
405 Msg->msgnum = msgnum;
406 FoundCharset = NewStrBuf();
407 while ((StrBuf_ServGetln(Buf)>=0) && !Done) {
408 if ( (StrLength(Buf)==3) &&
409 !strcmp(ChrPtr(Buf), "000"))
414 wprintf(_("unexpected end of message"));
415 wprintf(" (1)</i><br /><br />\n");
419 DestroyMessageSummary(Msg);
420 FreeStrBuf(&FoundCharset);
428 case 0:/* Citadel Message Headers */
429 if (StrLength(Buf) == 0) {
433 StrBufExtract_token(Token, Buf, 0, '=');
434 StrBufCutLeft(Buf, StrLength(Token) + 1);
436 lprintf(1, ":: [%s] = [%s]\n", ChrPtr(Token), ChrPtr(Buf));
437 if (GetHash(MsgHeaderHandler, SKEY(Token), &vHdr) &&
439 Hdr = (headereval*)vHdr;
440 Hdr->evaluator(Msg, Buf, FoundCharset);
441 if (Hdr->Type == 1) {
445 else lprintf(1, "don't know how to handle message header[%s]\n", ChrPtr(Token));
447 case 1:/* Message Mime Header */
448 if (StrLength(Buf) == 0) {
450 if (Msg->MsgBody.ContentType == NULL)
451 /* end of header or no header? */
452 Msg->MsgBody.ContentType = NewStrBufPlain(HKEY("text/plain"));
453 /* usual end of mime header */
457 StrBufExtract_token(Token, Buf, 0, ':');
458 if (StrLength(Token) > 0) {
459 StrBufCutLeft(Buf, StrLength(Token) + 1);
460 lprintf(1, ":: [%s] = [%s]\n", ChrPtr(Token), ChrPtr(Buf));
461 if (GetHash(MsgHeaderHandler, SKEY(Token), &vHdr) &&
463 Hdr = (headereval*)vHdr;
464 Hdr->evaluator(Msg, Buf, FoundCharset);
469 case 2: /* Message Body */
471 if (Msg->MsgBody.size_known > 0) {
472 StrBuf_ServGetBLOB(Msg->MsgBody.Data, Msg->MsgBody.length);
474 /// todo: check next line, if not 000, append following lines
477 if (StrLength(Msg->MsgBody.Data) > 0)
478 StrBufAppendBufPlain(Msg->MsgBody.Data, "\n", 1, 0);
479 StrBufAppendBuf(Msg->MsgBody.Data, Buf, 0);
483 StrBufAppendBuf(Msg->MsgBody.Data, Buf, 0);
488 /* strip the bare contenttype, so we ommit charset etc. */
489 StrBufExtract_token(Buf, Msg->MsgBody.ContentType, 0, ';');
491 if (GetHash(MimeRenderHandler, SKEY(Buf), &vHdr) &&
493 RenderMimeFunc Render;
494 Render = (RenderMimeFunc)vHdr;
495 Render(&Msg->MsgBody, NULL, FoundCharset);
499 if (StrLength(Msg->reply_references)> 0) {
500 /* Trim down excessively long lists of thread references. We eliminate the
501 * second one in the list so that the thread root remains intact.
503 int rrtok = num_tokens(ChrPtr(Msg->reply_references), '|');
504 int rrlen = StrLength(Msg->reply_references);
505 if ( ((rrtok >= 3) && (rrlen > 900)) || (rrtok > 10) ) {
506 remove_token(reply_references, 1, '|');////todo
510 /* Generate a reply-to address */
511 if (StrLength(Msg->Rfca) > 0) {
512 if (Msg->reply_to == NULL)
513 Msg->reply_to = NewStrBuf();
514 if (StrLength(Msg->from) > 0) {
515 StrBufPrintf(Msg->reply_to, "%s <%s>", ChrPtr(Msg->from), ChrPtr(Msg->Rfca));
518 FlushStrBuf(Msg->reply_to);
519 StrBufAppendBuf(Msg->reply_to, Msg->Rfca, 0);
524 if ((StrLength(Msg->OtherNode)>0) &&
525 (strcasecmp(ChrPtr(Msg->OtherNode), serv_info.serv_nodename)) &&
526 (strcasecmp(ChrPtr(Msg->OtherNode), serv_info.serv_humannode)) )
528 if (Msg->reply_to == NULL)
529 Msg->reply_to = NewStrBuf();
530 StrBufPrintf(Msg->reply_to,
533 ChrPtr(Msg->OtherNode));
536 if (Msg->reply_to == NULL)
537 Msg->reply_to = NewStrBuf();
538 FlushStrBuf(Msg->reply_to);
539 StrBufAppendBuf(Msg->reply_to, Msg->from, 0);
542 DoTemplate(HKEY("view_message"), NULL, Msg, CTX_MAILSUM);
546 //// put message renderer lookup here.
547 ///ENDBODY: /* If there are attached submessages, display them now... */
549 /// if ( (!IsEmptyStr(mime_submessages)) && (!section[0]) ) {
550 /// for (i=0; i<num_tokens(mime_submessages, '|'); ++i) {
551 /// extract_token(buf, mime_submessages, i, '|', sizeof buf);
552 /// /** use printable_view to suppress buttons */
553 /// wprintf("<blockquote>");
554 /// read_message(msgnum, 1, buf);
555 /// wprintf("</blockquote>");
560 /* Afterwards, offer links to download attachments 'n' such */
561 if ( (num_attach_links > 0) && (!section[0]) ) {
562 for (i=0; i<num_attach_links; ++i) {
563 if (strcasecmp(attach_links[i].partnum, msg4_partnum)) {
564 wprintf("%s", attach_links[i].html);
569 /* Handler for vCard parts */
570 if (!IsEmptyStr(vcard_partnum)) {
571 part_source = load_mimepart(msgnum, vcard_partnum);
572 if (part_source != NULL) {
574 /** If it's my vCard I can edit it */
575 if ( (!strcasecmp(WC->wc_roomname, USERCONFIGROOM))
576 || (!strcasecmp(&WC->wc_roomname[11], USERCONFIGROOM))
577 || (WC->wc_view == VIEW_ADDRESSBOOK)
579 wprintf("<a href=\"edit_vcard?msgnum=%ld&partnum=%s\">",
580 msgnum, vcard_partnum);
581 wprintf("[%s]</a>", _("edit"));
584 /* In all cases, display the full card */
585 display_vcard(WC->WBuf, part_source, 0, 1, NULL,msgnum);
589 /* Handler for calendar parts */
590 if (!IsEmptyStr(cal_partnum)) {
600 /* end everythingamundo table */
601 if (!printable_view) {
605 if (num_attach_links > 0) {
608 DestroyMessageSummary(Msg);
609 FreeStrBuf(&FoundCharset);
617 * Unadorned HTML output of an individual message, suitable
618 * for placing in a hidden iframe, for printing, or whatever
620 * msgnum_as_string == Message number, as a string instead of as a long int
622 void embed_message(void) {
625 msgnum = StrTol(WC->UrlFragment1);
626 read_message(msgnum, 0, "");
631 * Printable view of a message
633 * msgnum_as_string == Message number, as a string instead of as a long int
635 void print_message(void) {
638 msgnum = StrTol(WC->UrlFragment1);
639 output_headers(0, 0, 0, 0, 0, 0);
641 hprintf("Content-type: text/html\r\n"
643 "Connection: close\r\n",
647 wprintf("\r\n<html>\n<head><title>");
648 escputs(WC->wc_fullname);
649 wprintf("</title></head>\n"
650 "<body onLoad=\" window.print(); window.close(); \">\n"
653 read_message(msgnum, 1, "");
655 wprintf("\n</body></html>\n\n");
660 * Mobile browser view of message
662 * @param msg_num_as_string Message number as a string instead of as a long int
664 void mobile_message_view(void) {
666 msgnum = StrTol(WC->UrlFragment1);
667 output_headers(1, 0, 0, 0, 0, 1);
669 do_template("msgcontrols", NULL);
670 read_message(msgnum,1, "");
675 * \brief Display a message's headers
677 * \param msgnum_as_string Message number, as a string instead of as a long int
679 void display_headers(void) {
683 msgnum = StrTol(WC->UrlFragment1);
684 output_headers(0, 0, 0, 0, 0, 0);
686 hprintf("Content-type: text/plain\r\n"
688 "Connection: close\r\n",
692 serv_printf("MSG2 %ld|3", msgnum);
693 serv_getln(buf, sizeof buf);
695 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
696 wprintf("%s\n", buf);
706 * \brief Read message in simple, JavaScript-embeddable form for 'forward'
707 * or 'reply quoted' operations.
709 * NOTE: it is VITALLY IMPORTANT that we output no single-quotes or linebreaks
710 * in this function. Doing so would throw a JavaScript error in the
711 * 'supplied text' argument to the editor.
713 * \param msgnum Message number of the message we want to quote
714 * \param forward_attachments Nonzero if we want attachments to be forwarded
716 void pullquote_message(long msgnum, int forward_attachments, int include_headers) {
718 char mime_partnum[256];
719 char mime_filename[256];
720 char mime_content_type[256];
721 char mime_charset[256];
722 char mime_disposition[256];
724 char *attachments = NULL;
726 int num_attachments = 0;
727 struct wc_attachment *att, *aptr;
728 char m_subject[1024];
740 iconv_t ic = (iconv_t)(-1) ;
741 char *ibuf; /**< Buffer of characters to be converted */
742 char *obuf; /**< Buffer for converted characters */
743 size_t ibuflen; /**< Length of input buffer */
744 size_t obuflen; /**< Length of output buffer */
745 char *osav; /**< Saved pointer to output buffer */
751 strcpy(reply_to, "");
752 strcpy(mime_content_type, "text/plain");
753 strcpy(mime_charset, "us-ascii");
755 serv_printf("MSG4 %ld", msgnum);
756 serv_getln(buf, sizeof buf);
758 wprintf(_("ERROR:"));
759 wprintf("%s<br />", &buf[4]);
763 strcpy(m_subject, "");
765 while (serv_getln(buf, sizeof buf), strcasecmp(buf, "text")) {
766 if (!strcmp(buf, "000")) {
767 wprintf("%s (3)", _("unexpected end of message"));
770 if (include_headers) {
771 if (!strncasecmp(buf, "nhdr=yes", 8))
775 if (!strncasecmp(buf, "type=", 5))
776 format_type = atoi(&buf[5]);
777 if (!strncasecmp(buf, "from=", 5)) {
778 strcpy(from, &buf[5]);
780 utf8ify_rfc822_string(from);
783 if (!strncasecmp(buf, "subj=", 5)) {
784 strcpy(m_subject, &buf[5]);
786 if ((!strncasecmp(buf, "hnod=", 5))
787 && (strcasecmp(&buf[5], serv_info.serv_humannode))) {
788 wprintf("(%s) ", &buf[5]);
790 if ((!strncasecmp(buf, "room=", 5))
791 && (strcasecmp(&buf[5], WC->wc_roomname))
792 && (!IsEmptyStr(&buf[5])) ) {
794 wprintf("%s> ", &buf[5]);
796 if (!strncasecmp(buf, "rfca=", 5)) {
797 strcpy(rfca, &buf[5]);
802 if (!strncasecmp(buf, "node=", 5)) {
803 strcpy(node, &buf[5]);
804 if ( ((WC->room_flags & QR_NETWORK)
805 || ((strcasecmp(&buf[5], serv_info.serv_nodename)
806 && (strcasecmp(&buf[5], serv_info.serv_fqdn)))))
807 && (IsEmptyStr(rfca))
809 wprintf("@%s ", &buf[5]);
812 if (!strncasecmp(buf, "rcpt=", 5)) {
815 utf8ify_rfc822_string(to);
818 if (!strncasecmp(buf, "time=", 5)) {
819 webcit_fmt_date(now, atol(&buf[5]), 0);
825 * Save attachment info for later. We can't start downloading them
826 * yet because we're in the middle of a server transaction.
828 if (!strncasecmp(buf, "part=", 5)) {
829 ptr = malloc( (strlen(buf) + ((attachments != NULL) ? strlen(attachments) : 0)) ) ;
832 sprintf(ptr, "%s%s\n",
833 ((attachments != NULL) ? attachments : ""),
838 lprintf(9, "attachments=<%s>\n", attachments);
844 if (include_headers) {
847 utf8ify_rfc822_string(m_subject);
848 if (!IsEmptyStr(m_subject)) {
849 wprintf(_("Subject:"));
851 msgescputs(m_subject);
862 * Learn the content type
864 strcpy(mime_content_type, "text/plain");
865 while (serv_getln(buf, sizeof buf), (!IsEmptyStr(buf))) {
866 if (!strcmp(buf, "000")) {
867 wprintf("%s (4)", _("unexpected end of message"));
870 if (!strncasecmp(buf, "Content-type: ", 14)) {
872 safestrncpy(mime_content_type, &buf[14],
873 sizeof(mime_content_type));
874 for (i=0; i<strlen(mime_content_type); ++i) {
875 if (!strncasecmp(&mime_content_type[i], "charset=", 8)) {
876 safestrncpy(mime_charset, &mime_content_type[i+8],
877 sizeof mime_charset);
880 len = strlen(mime_content_type);
881 for (i=0; i<len; ++i) {
882 if (mime_content_type[i] == ';') {
883 mime_content_type[i] = 0;
887 len = strlen(mime_charset);
888 for (i=0; i<len; ++i) {
889 if (mime_charset[i] == ';') {
897 /** Set up a character set conversion if we need to (and if we can) */
899 if ( (strcasecmp(mime_charset, "us-ascii"))
900 && (strcasecmp(mime_charset, "UTF-8"))
901 && (strcasecmp(mime_charset, ""))
903 ctdl_iconv_open("UTF-8", mime_charset, &ic);
904 if (ic == (iconv_t)(-1) ) {
905 lprintf(5, "%s:%d iconv_open(%s, %s) failed: %s\n",
906 __FILE__, __LINE__, "UTF-8", mime_charset, strerror(errno));
911 /** Messages in legacy Citadel variformat get handled thusly... */
912 if (!strcasecmp(mime_content_type, "text/x-citadel-variformat")) {
916 /* Boring old 80-column fixed format text gets handled this way... */
917 else if (!strcasecmp(mime_content_type, "text/plain")) {
918 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
921 if ((len > 0) && (buf[len-1] == '\n')) buf[--len] = 0;
922 if ((len > 0) && (buf[len-1] == '\r')) buf[--len] = 0;
925 if (ic != (iconv_t)(-1) ) {
929 obuf = (char *) malloc(obuflen);
931 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
932 osav[SIZ-obuflen] = 0;
933 safestrncpy(buf, osav, sizeof buf);
939 while ((!IsEmptyStr(buf)) && (isspace(buf[len - 1])))
942 ((!strncmp(buf, ">", 1)) || (!strncmp(buf, " >", 2)) )) {
943 wprintf("<blockquote>");
945 } else if ((bq == 1) &&
946 (strncmp(buf, ">", 1)) && (strncmp(buf, " >", 2)) ) {
947 wprintf("</blockquote>");
951 url(buf, sizeof(buf));
953 wprintf("</tt><br />");
955 wprintf("</i><br />");
958 /** HTML just gets escaped and stuffed back into the editor */
959 else if (!strcasecmp(mime_content_type, "text/html")) {
960 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
964 }//// TODO: charset? utf8?
966 /** Unknown weirdness ... don't know how to handle this content type */
968 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { }
972 /** end of body handler */
975 * If there were attachments, we have to download them and insert them
976 * into the attachment chain for the forwarded message we are composing.
978 if ( (forward_attachments) && (num_attachments) ) {
979 for (i=0; i<num_attachments; ++i) {
980 extract_token(buf, attachments, i, '\n', sizeof buf);
981 extract_token(mime_filename, buf, 1, '|', sizeof mime_filename);
982 extract_token(mime_partnum, buf, 2, '|', sizeof mime_partnum);
983 extract_token(mime_disposition, buf, 3, '|', sizeof mime_disposition);
984 extract_token(mime_content_type, buf, 4, '|', sizeof mime_content_type);
985 mime_length = extract_int(buf, 5);
988 * tracing ... uncomment if necessary
991 lprintf(9, "fwd filename: %s\n", mime_filename);
992 lprintf(9, "fwd partnum : %s\n", mime_partnum);
993 lprintf(9, "fwd conttype: %s\n", mime_content_type);
994 lprintf(9, "fwd dispose : %s\n", mime_disposition);
995 lprintf(9, "fwd length : %d\n", mime_length);
997 if ( (!strcasecmp(mime_disposition, "inline"))
998 || (!strcasecmp(mime_disposition, "attachment")) ) {
1000 /* Create an attachment struct from this mime part... */
1001 att = malloc(sizeof(struct wc_attachment));
1002 memset(att, 0, sizeof(struct wc_attachment));
1003 att->length = mime_length;
1004 strcpy(att->content_type, mime_content_type);
1005 strcpy(att->filename, mime_filename);
1007 att->data = load_mimepart(msgnum, mime_partnum);
1009 /* And add it to the list. */
1010 if (WC->first_attachment == NULL) {
1011 WC->first_attachment = att;
1014 aptr = WC->first_attachment;
1015 while (aptr->next != NULL) aptr = aptr->next;
1024 if (ic != (iconv_t)(-1) ) {
1029 if (attachments != NULL) {
1037 void EvaluateMimePart(message_summary *Sum, StrBuf *Buf)
1040 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
1041 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
1042 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
1043 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
1044 mime_length = extract_int(&buf[5], 5);
1046 if ( (!strcasecmp(mime_content_type, "text/x-vcard"))
1047 || (!strcasecmp(mime_content_type, "text/vcard")) ) {
1048 strcpy(vcard_partnum, mime_partnum);
1053 message_summary *ReadOneMessageSummary(StrBuf *RawMessage, const char *DefaultSubject, long MsgNum)
1056 MsgPartEvaluatorFunc Eval;
1057 message_summary *Msg;
1066 serv_printf("MSG0 %ld|1", MsgNum); /* ask for headers only */
1068 StrBuf_ServGetln(Buf);
1069 if (GetServerStatus(Buf, NULL) == 1) {
1074 Msg = (message_summary*)malloc(sizeof(message_summary));
1075 memset(Msg, 0, sizeof(message_summary));
1076 while (len = StrBuf_ServGetln(Buf),
1078 strcmp(ChrPtr(Buf), "000")== 0)){
1080 ebuf = strchr(ChrPtr(Buf), '=');
1082 if (GetHash(MsgEvaluators, buf, nBuf, &vEval) && vEval != NULL) {
1083 Eval = (MsgPartEvaluatorFunc) vEval;
1084 StrBufCutLeft(Buf, nBuf + 1);
1087 else lprintf(1, "Don't know how to handle Message Headerline [%s]", ChrPtr(Buf));
1094 * \brief display the adressbook overview
1095 * \param msgnum the citadel message number
1096 * \param alpha what????
1098 void display_addressbook(long msgnum, char alpha) {
1100 /* char mime_partnum[SIZ]; */
1101 /* char mime_filename[SIZ]; */
1102 /* char mime_content_type[SIZ]; */
1103 ///char mime_disposition[SIZ];
1105 char vcard_partnum[SIZ];
1106 char *vcard_source = NULL;
1107 message_summary summ;////TODO: this will leak
1109 memset(&summ, 0, sizeof(summ));
1110 ///safestrncpy(summ.subj, _("(no subject)"), sizeof summ.subj);
1111 ///Load Message headers
1113 if (!IsEmptyStr(vcard_partnum)) {
1114 vcard_source = load_mimepart(msgnum, vcard_partnum);
1115 if (vcard_source != NULL) {
1117 /** Display the summary line */
1118 display_vcard(WC->WBuf, vcard_source, alpha, 0, NULL,msgnum);
1120 /** If it's my vCard I can edit it */
1121 if ( (!strcasecmp(WC->wc_roomname, USERCONFIGROOM))
1122 || (!strcasecmp(&WC->wc_roomname[11], USERCONFIGROOM))
1123 || (WC->wc_view == VIEW_ADDRESSBOOK)
1125 wprintf("<a href=\"edit_vcard?"
1126 "msgnum=%ld&partnum=%s\">",
1127 msgnum, vcard_partnum);
1128 wprintf("[%s]</a>", _("edit"));
1140 * \brief If it's an old "Firstname Lastname" style record, try to convert it.
1141 * \param namebuf name to analyze, reverse if nescessary
1143 void lastfirst_firstlast(char *namebuf) {
1144 char firstname[SIZ];
1148 if (namebuf == NULL) return;
1149 if (strchr(namebuf, ';') != NULL) return;
1151 i = num_tokens(namebuf, ' ');
1154 extract_token(lastname, namebuf, i-1, ' ', sizeof lastname);
1155 remove_token(namebuf, i-1, ' ');
1156 strcpy(firstname, namebuf);
1157 sprintf(namebuf, "%s; %s", lastname, firstname);
1161 * \brief fetch what??? name
1162 * \param msgnum the citadel message number
1163 * \param namebuf where to put the name in???
1165 void fetch_ab_name(message_summary *Msg, char *namebuf) {
1167 char mime_partnum[SIZ];
1168 char mime_filename[SIZ];
1169 char mime_content_type[SIZ];
1170 char mime_disposition[SIZ];
1172 char vcard_partnum[SIZ];
1173 char *vcard_source = NULL;
1175 message_summary summ;/// TODO this will lak
1177 if (namebuf == NULL) return;
1178 strcpy(namebuf, "");
1180 memset(&summ, 0, sizeof(summ));
1181 //////safestrncpy(summ.subj, "(no subject)", sizeof summ.subj);
1183 sprintf(buf, "MSG0 %ld|0", Msg->msgnum); /** unfortunately we need the mime info now */
1185 serv_getln(buf, sizeof buf);
1186 if (buf[0] != '1') return;
1188 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1189 if (!strncasecmp(buf, "part=", 5)) {
1190 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
1191 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
1192 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
1193 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
1194 mime_length = extract_int(&buf[5], 5);
1196 if ( (!strcasecmp(mime_content_type, "text/x-vcard"))
1197 || (!strcasecmp(mime_content_type, "text/vcard")) ) {
1198 strcpy(vcard_partnum, mime_partnum);
1204 if (!IsEmptyStr(vcard_partnum)) {
1205 vcard_source = load_mimepart(Msg->msgnum, vcard_partnum);
1206 if (vcard_source != NULL) {
1208 /* Grab the name off the card */
1209 display_vcard(WC->WBuf, vcard_source, 0, 0, namebuf, Msg->msgnum);
1215 lastfirst_firstlast(namebuf);
1217 len = strlen(namebuf);
1218 for (i=0; i<len; ++i) {
1219 if (namebuf[i] != ';') return;
1221 strcpy(namebuf, _("(no name)"));
1229 * load message pointers from the server for a "read messages" operation
1231 * servcmd: the citadel command to send to the citserver
1232 * with_headers: also include some of the headers with the message numbers (more expensive)
1234 int load_msg_ptrs(char *servcmd, int with_headers)
1236 StrBuf* FoundCharset = NULL;
1237 struct wcsession *WCC = WC;
1238 message_summary *Msg;
1241 ///time_t datestamp;
1242 //char fullname[128];
1243 //char nodename[128];
1244 //char inetaddr[128];
1245 //char subject[1024];
1252 ////int num_summ_alloc = 0;
1254 if (WCC->summ != NULL) {
1255 if (WCC->summ != NULL)
1256 DeleteHash(&WCC->summ);
1258 WCC->summ = NewHash(1, Flathash);
1260 maxload = 1000;/// TODO
1264 StrBuf_ServGetln(Buf);
1265 if (GetServerStatus(Buf, NULL) != 1) {
1269 // TODO if (with_headers) { //// TODO: Have Attachments?
1271 while (len = StrBuf_ServGetln(Buf),
1273 strcmp(ChrPtr(Buf), "000")!= 0))
1275 if (nummsgs < maxload) {
1276 Msg = (message_summary*)malloc(sizeof(message_summary));
1277 memset(Msg, 0, sizeof(message_summary));
1279 Msg->msgnum = StrBufExtract_long(Buf, 0, '|');
1280 Msg->date = StrBufExtract_long(Buf, 1, '|');
1282 Msg->from = NewStrBufPlain(NULL, StrLength(Buf));
1283 StrBufExtract_token(Buf2, Buf, 2, '|');
1284 if (StrLength(Buf2) != 0) {
1285 /** Handle senders with RFC2047 encoding */
1286 StrBuf_RFC822_to_Utf8(Msg->from, Buf2, WCC->DefaultCharset, FoundCharset);
1290 StrBufExtract_token(Buf2, Buf, 3, '|');
1291 if ((StrLength(Buf2) !=0 ) &&
1292 ( ((WCC->room_flags & QR_NETWORK)
1293 || ((strcasecmp(ChrPtr(Buf2), serv_info.serv_nodename)
1294 && (strcasecmp(ChrPtr(Buf2), serv_info.serv_fqdn)))))))
1296 StrBufAppendBufPlain(Msg->from, HKEY(" @ "), 0);
1297 StrBufAppendBuf(Msg->from, Buf2, 0);
1301 StrBufExtract_token(Msg->inetaddr, Buf, 4, '|');
1304 Msg->subj = NewStrBufPlain(NULL, StrLength(Buf));
1305 StrBufExtract_token(Buf2, Buf, 5, '|');
1306 if (StrLength(Buf2) == 0)
1307 StrBufAppendBufPlain(Msg->subj, _("(no subj)"), 0, -1);
1309 StrBuf_RFC822_to_Utf8(Msg->subj, Buf2, WCC->DefaultCharset, FoundCharset);
1310 if ((StrLength(Msg->subj) > 75) &&
1311 (StrBuf_Utf8StrLen(Msg->subj) > 75)) {
1312 StrBuf_Utf8StrCut(Msg->subj, 72);
1313 StrBufAppendBufPlain(Msg->subj, HKEY("..."), 0);
1318 if ((StrLength(Msg->from) > 25) &&
1319 (StrBuf_Utf8StrLen(Msg->from) > 25)) {
1320 StrBuf_Utf8StrCut(Msg->from, 23);
1321 StrBufAppendBufPlain(Msg->from, HKEY("..."), 0);
1323 Put(WCC->summ, (const char*)&Msg->msgnum, sizeof(Msg->msgnum), Msg, DestroyMessageSummary);
1338 * command loop for reading messages
1340 * Set oper to "readnew" or "readold" or "readfwd" or "headers"
1342 void readloop(char *oper)
1345 message_summary *Msg;
1354 long *displayed_msgs = NULL;
1355 int num_displayed = 0;
1357 int is_addressbook = 0;
1358 int is_singlecard = 0;
1359 int is_calendar = 0;
1360 struct calview calv;
1365 int lowest_displayed = (-1);
1366 int highest_displayed = 0;
1367 addrbookent *addrbook = NULL;
1369 const StrBuf *sortby = NULL;
1371 int SortBy = eRDate;
1372 const StrBuf *sortpref_value;
1373 int bbs_reverse = 0;
1374 struct wcsession *WCC = WC; /* This is done to make it run faster; WC is a function */
1376 const char *HashKey;
1379 if (WCC->wc_view == VIEW_WIKI) {
1380 sprintf(buf, "wiki?room=%s&page=home", WCC->wc_roomname);
1385 startmsg = lbstr("startmsg");
1386 maxmsgs = ibstr("maxmsgs");
1387 is_summary = (ibstr("is_summary") && !WCC->is_mobile);
1388 if (maxmsgs == 0) maxmsgs = DEFAULT_MAXMSGS;
1390 sortpref_value = get_room_pref("sort");
1392 sortby = sbstr("sortby");
1393 if ( (!IsEmptyStr(ChrPtr(sortby))) &&
1394 (strcasecmp(ChrPtr(sortby), ChrPtr(sortpref_value)) != 0)) {
1395 set_room_pref("sort", NewStrBufDup(sortby), 1);
1396 sortpref_value = NULL;
1397 sortpref_value = sortby;
1400 SortBy = StrToESort(sortpref_value);
1401 /* message board sort */
1402 if (SortBy == eReverse) {
1409 output_headers(1, 1, 1, 0, 0, 0);
1412 * When in summary mode, always show ALL messages instead of just
1413 * new or old. Otherwise, show what the user asked for.
1415 if (!strcmp(oper, "readnew")) {
1416 strcpy(cmd, "MSGS NEW");
1418 else if (!strcmp(oper, "readold")) {
1419 strcpy(cmd, "MSGS OLD");
1421 else if (!strcmp(oper, "do_search")) {
1422 snprintf(cmd, sizeof(cmd), "MSGS SEARCH|%s", bstr("query"));
1425 strcpy(cmd, "MSGS ALL");
1428 if ((WCC->wc_view == VIEW_MAILBOX) && (maxmsgs > 1) && !WCC->is_mobile) {
1430 if (!strcmp(oper, "do_search")) {
1431 snprintf(cmd, sizeof(cmd), "MSGS SEARCH|%s", bstr("query"));
1434 strcpy(cmd, "MSGS ALL");
1438 if ((WCC->wc_view == VIEW_ADDRESSBOOK) && (maxmsgs > 1)) {
1440 if (!strcmp(oper, "do_search")) {
1441 snprintf(cmd, sizeof(cmd), "MSGS SEARCH|%s", bstr("query"));
1444 strcpy(cmd, "MSGS ALL");
1449 if (is_summary) { /**< fetch header summary */
1450 snprintf(cmd, sizeof(cmd), "MSGS %s|%s||1",
1451 (!strcmp(oper, "do_search") ? "SEARCH" : "ALL"),
1452 (!strcmp(oper, "do_search") ? bstr("query") : "")
1457 if (WCC->is_mobile) {
1459 snprintf(cmd, sizeof(cmd), "MSGS %s|%s||1",
1460 (!strcmp(oper, "do_search") ? "SEARCH" : "ALL"),
1461 (!strcmp(oper, "do_search") ? bstr("query") : "")
1467 * Are we doing a summary view? If so, we need to know old messages
1468 * and new messages, so we can do that pretty boldface thing for the
1471 strcpy(old_msgs, "");
1472 if ((is_summary) || (WCC->wc_default_view == VIEW_CALENDAR) || WCC->is_mobile){
1474 serv_getln(buf, sizeof buf);
1475 if (buf[0] == '2') {
1476 strcpy(old_msgs, &buf[4]);
1480 is_singlecard = ibstr("is_singlecard");
1482 if (WCC->wc_default_view == VIEW_CALENDAR) { /**< calendar */
1484 strcpy(cmd, "MSGS ALL|||1");
1486 parse_calendar_view_request(&calv);
1488 if (WCC->wc_default_view == VIEW_TASKS) { /**< tasks */
1490 strcpy(cmd, "MSGS ALL");
1493 if (WCC->wc_default_view == VIEW_NOTES) { /**< notes */
1495 strcpy(cmd, "MSGS ALL");
1500 wprintf("<div id=\"new_notes_here\"></div>\n");
1503 nummsgs = load_msg_ptrs(cmd, (is_summary || WCC->is_mobile));
1506 if ((!is_tasks) && (!is_calendar) && (!is_notes) && (!is_addressbook)) {
1507 wprintf("<div align=\"center\"><br /><em>");
1508 if (!strcmp(oper, "readnew")) {
1509 wprintf(_("No new messages."));
1510 } else if (!strcmp(oper, "readold")) {
1511 wprintf(_("No old messages."));
1513 wprintf(_("No messages here."));
1515 wprintf("</em><br /></div>\n");
1521 if ((is_summary) || (WCC->wc_default_view == VIEW_CALENDAR) || WCC->is_mobile){
1523 message_summary *Msg;
1525 at = GetNewHashPos();
1526 while (GetNextHashPos(WCC->summ, at, &HKLen, &HashKey, &vMsg)) {
1527 /** Are you a new message, or an old message? */
1528 Msg = (message_summary*) vMsg;
1530 if (is_msg_in_mset(old_msgs, Msg->msgnum)) {
1541 if (startmsg == 0L) {
1543 startmsg = WCC->msgarr[(nummsgs >= maxmsgs) ? (nummsgs - maxmsgs) : 0];
1546 startmsg = WCC->msgarr[0];
1550 if (is_summary || WCC->is_mobile) {
1551 SortByPayload(WCC->summ, SortFuncs[SortBy]);
1556 wprintf("<script language=\"javascript\" type=\"text/javascript\">"
1557 " document.onkeydown = CtdlMsgListKeyPress; "
1558 " if (document.layers) { "
1559 " document.captureEvents(Event.KEYPRESS); "
1564 /** note that Date and Delete are now in the same column */
1565 wprintf("<div id=\"message_list_hdr\">"
1566 "<div class=\"fix_scrollbar_bug\">"
1567 "<table cellspacing=0 style=\"width:100%%\">"
1570 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"
1571 "<th width=%d%%>%s <a href=\"readfwd?startmsg=1?maxmsgs=9999999?is_summary=1?sortby=%s\"><img border=\"0\" src=\"%s\" /></a> </th>\n"
1572 "<th width=%d%%>%s <a href=\"readfwd?startmsg=1?maxmsgs=9999999?is_summary=1?sortby=%s\"><img border=\"0\" src=\"%s\" /></a> \n"
1574 "<input type=\"submit\" name=\"delete_button\" id=\"delbutton\" "
1575 " onClick=\"CtdlDeleteSelectedMessages(event)\" "
1582 SortByStrings[SubjectInvertSortString[SortBy]],
1583 SortIcons[SortSubjectToIcon[SortBy]],
1584 SENDER_COL_WIDTH_PCT,
1586 SortByStrings[SenderInvertSortString[SortBy]],
1587 SortIcons[SortSenderToIcon[SortBy]],
1588 DATE_PLUS_BUTTONS_WIDTH_PCT,
1590 SortByStrings[DateInvertSortString[SortBy]],
1591 SortIcons[SortDateToIcon[SortBy]],
1594 wprintf("</table></div></div>\n");
1595 wprintf("<div id=\"message_list\">"
1597 "<div class=\"fix_scrollbar_bug\">\n"
1598 "<table class=\"mailbox_summary\" id=\"summary_headers\" "
1599 "cellspacing=0 style=\"width:100%%;-moz-user-select:none;\">"
1601 } else if (WCC->is_mobile) {
1602 wprintf("<div id=\"message_list\">");
1607 * Set the "is_bbview" variable if it appears that we are looking at
1608 * a classic bulletin board view.
1610 if ((!is_tasks) && (!is_calendar) && (!is_addressbook)
1611 && (!is_notes) && (!is_singlecard) && (!is_summary)) {
1616 * If we're not currently looking at ALL requested
1617 * messages, then display the selector bar
1620 /** begin bbview scroller */
1621 wprintf("<form name=\"msgomatictop\" class=\"selector_top\" > \n <p>");
1622 wprintf(_("Reading #"));//// TODO this isn't used, should it? : , lowest_displayed, highest_displayed);
1624 wprintf("<select name=\"whichones\" size=\"1\" "
1625 "OnChange=\"location.href=msgomatictop.whichones.options"
1626 "[selectedIndex].value\">\n");
1629 for (b=nummsgs-1; b>=0; b = b - maxmsgs) {
1631 lo = b - maxmsgs + 2;
1633 wprintf("<option %s value="
1638 "%d-%d</option> \n",
1639 ((WCC->msgarr[lo-1] == startmsg) ? "selected" : ""),
1648 for (b=0; b<nummsgs; b = b + maxmsgs) {
1650 hi = b + maxmsgs + 1;
1651 if (hi > nummsgs) hi = nummsgs;
1652 wprintf("<option %s value="
1657 "%d-%d</option> \n",
1658 ((WCC->msgarr[b] == startmsg) ? "selected" : ""),
1667 wprintf("<option value=\"%s?startmsg=%ld"
1668 "&maxmsgs=9999999&is_summary=%d\">",
1670 WCC->msgarr[0], is_summary);
1672 wprintf("</option>");
1673 wprintf("</select> ");
1674 wprintf(_("of %d messages."), nummsgs);
1676 /** forward/reverse */
1677 wprintf("<input type=\"radio\" %s name=\"direction\" value=\"\""
1678 "OnChange=\"location.href='%s?sortby=forward'\"",
1679 (bbs_reverse ? "" : "checked"),
1683 wprintf(_("oldest to newest"));
1684 wprintf(" ");
1686 wprintf("<input type=\"radio\" %s name=\"direction\" value=\"\""
1687 "OnChange=\"location.href='%s?sortby=reverse'\"",
1688 (bbs_reverse ? "checked" : ""),
1692 wprintf(_("newest to oldest"));
1695 wprintf("</p></form>\n");
1696 /** end bbview scroller */
1699 at = GetNewHashPos();
1700 while (GetNextHashPos(WCC->summ, at, &HKLen, &HashKey, &vMsg)) {
1701 Msg = (message_summary*) vMsg;
1702 if ((Msg->msgnum >= startmsg) && (num_displayed < maxmsgs)) {
1704 /** Display the message */
1706 DoTemplate(HKEY("section_mailsummary"), NULL, Msg, CTX_MAILSUM);
1708 else if (is_addressbook) {
1709 fetch_ab_name(Msg, buf);
1711 addrbook = realloc(addrbook,
1712 (sizeof(addrbookent) * num_ab) );
1713 safestrncpy(addrbook[num_ab-1].ab_name, buf,
1714 sizeof(addrbook[num_ab-1].ab_name));
1715 addrbook[num_ab-1].ab_msgnum = Msg->msgnum;
1717 else if (is_calendar) {
1718 load_calendar_item(Msg, Msg->is_new, &calv);
1720 else if (is_tasks) {
1721 display_task(Msg, Msg->is_new);
1723 else if (is_notes) {
1724 display_note(Msg, Msg->is_new);
1725 } else if (WCC->is_mobile) {
1726 DoTemplate(HKEY("section_mailsummary"), NULL, Msg, CTX_MAILSUM);
1729 if (displayed_msgs == NULL) {
1730 displayed_msgs = malloc(sizeof(long) *
1731 (maxmsgs<nummsgs ? maxmsgs : nummsgs));
1733 displayed_msgs[num_displayed] = Msg->msgnum;
1736 if (lowest_displayed < 0) lowest_displayed = a;
1737 highest_displayed = a;
1745 if (displayed_msgs != NULL) {
1747 qsort(displayed_msgs, num_displayed, sizeof(long), longcmp_r);
1750 /** if we do a split bbview in the future, begin messages div here */
1752 for (a=0; a<num_displayed; ++a) {
1753 read_message(displayed_msgs[a], 0, "");
1756 /** if we do a split bbview in the future, end messages div here */
1758 free(displayed_msgs);
1759 displayed_msgs = NULL;
1764 "</div>\n"); /**< end of 'fix_scrollbar_bug' div */
1765 wprintf("</div>"); /**< end of 'message_list' div */
1767 /** Here's the grab-it-to-resize-the-message-list widget */
1768 wprintf("<div id=\"resize_msglist\" "
1769 "onMouseDown=\"CtdlResizeMsgListMouseDown(event)\">"
1770 "<div class=\"fix_scrollbar_bug\"> <hr>"
1774 wprintf("<div id=\"preview_pane\">"); /**< The preview pane will initially be empty */
1775 } else if (WCC->is_mobile) {
1780 * Bump these because although we're thinking in zero base, the user
1781 * is a drooling idiot and is thinking in one base.
1784 ++highest_displayed;
1787 * If we're not currently looking at ALL requested
1788 * messages, then display the selector bar
1791 /** begin bbview scroller */
1792 wprintf("<form name=\"msgomatic\" class=\"selector_bottom\" > \n <p>");
1793 wprintf(_("Reading #")); /// TODO: this isn't used: , lowest_displayed, highest_displayed);
1795 wprintf("<select name=\"whichones\" size=\"1\" "
1796 "OnChange=\"location.href=msgomatic.whichones.options"
1797 "[selectedIndex].value\">\n");
1800 for (b=nummsgs-1; b>=0; b = b - maxmsgs) {
1802 lo = b - maxmsgs + 2;
1804 wprintf("<option %s value="
1809 "%d-%d</option> \n",
1810 ((WCC->msgarr[lo-1] == startmsg) ? "selected" : ""),
1819 for (b=0; b<nummsgs; b = b + maxmsgs) {
1821 hi = b + maxmsgs + 1;
1822 if (hi > nummsgs) hi = nummsgs;
1823 wprintf("<option %s value="
1828 "%d-%d</option> \n",
1829 ((WCC->msgarr[b] == startmsg) ? "selected" : ""),
1838 wprintf("<option value=\"%s&startmsg=%ld"
1839 "&maxmsgs=9999999&is_summary=%d\">",
1841 WCC->msgarr[0], is_summary);
1843 wprintf("</option>");
1844 wprintf("</select> ");
1845 wprintf(_("of %d messages."), nummsgs);
1847 /** forward/reverse */
1848 wprintf("<input type=\"radio\" %s name=\"direction\" value=\"\""
1849 "OnChange=\"location.href='%s&sortby=forward'\"",
1850 (bbs_reverse ? "" : "checked"),
1854 wprintf(_("oldest to newest"));
1855 wprintf(" ");
1856 wprintf("<input type=\"radio\" %s name=\"direction\" value=\"\""
1857 "OnChange=\"location.href='%s&sortby=reverse'\"",
1858 (bbs_reverse ? "checked" : ""),
1862 wprintf(_("newest to oldest"));
1865 wprintf("</p></form>\n");
1866 /** end bbview scroller */
1871 do_tasks_view(); /** Render the task list */
1875 render_calendar_view(&calv);
1878 if (is_addressbook) {
1879 do_addrbook_view(addrbook, num_ab); /** Render the address book */
1882 /** Note: wDumpContent() will output one additional </div> tag. */
1883 wprintf("</div>\n"); /** end of 'content' div */
1886 /** free the summary */
1887 if (WCC->summ != NULL) {
1888 DeleteHash(&WCC->summ);
1890 if (addrbook != NULL) free(addrbook);
1895 * Back end for post_message()
1896 * ... this is where the actual message gets transmitted to the server.
1898 void post_mime_to_server(void) {
1899 char top_boundary[SIZ];
1900 char alt_boundary[SIZ];
1901 int is_multipart = 0;
1903 struct wc_attachment *att;
1905 size_t encoded_length;
1906 size_t encoded_strlen;
1907 char *txtmail = NULL;
1909 sprintf(top_boundary, "Citadel--Multipart--%s--%04x--%04x",
1910 serv_info.serv_fqdn,
1914 sprintf(alt_boundary, "Citadel--Multipart--%s--%04x--%04x",
1915 serv_info.serv_fqdn,
1920 /* RFC2045 requires this, and some clients look for it... */
1921 serv_puts("MIME-Version: 1.0");
1922 serv_puts("X-Mailer: " PACKAGE_STRING);
1924 /* If there are attachments, we have to do multipart/mixed */
1925 if (WC->first_attachment != NULL) {
1930 /* Remember, serv_printf() appends an extra newline */
1931 serv_printf("Content-type: multipart/mixed; boundary=\"%s\"\n", top_boundary);
1932 serv_printf("This is a multipart message in MIME format.\n");
1933 serv_printf("--%s", top_boundary);
1936 /* Remember, serv_printf() appends an extra newline */
1937 serv_printf("Content-type: multipart/alternative; "
1938 "boundary=\"%s\"\n", alt_boundary);
1939 serv_printf("This is a multipart message in MIME format.\n");
1940 serv_printf("--%s", alt_boundary);
1942 serv_puts("Content-type: text/plain; charset=utf-8");
1943 serv_puts("Content-Transfer-Encoding: quoted-printable");
1945 txtmail = html_to_ascii(bstr("msgtext"), 0, 80, 0);
1946 text_to_server_qp(txtmail); /* Transmit message in quoted-printable encoding */
1949 serv_printf("--%s", alt_boundary);
1951 serv_puts("Content-type: text/html; charset=utf-8");
1952 serv_puts("Content-Transfer-Encoding: quoted-printable");
1954 serv_puts("<html><body>\r\n");
1955 text_to_server_qp(bstr("msgtext")); /* Transmit message in quoted-printable encoding */
1956 serv_puts("</body></html>\r\n");
1958 serv_printf("--%s--", alt_boundary);
1962 /* Add in the attachments */
1963 for (att = WC->first_attachment; att!=NULL; att=att->next) {
1965 encoded_length = ((att->length * 150) / 100);
1966 encoded = malloc(encoded_length);
1967 if (encoded == NULL) break;
1968 encoded_strlen = CtdlEncodeBase64(encoded, att->data, att->length, 1);
1970 serv_printf("--%s", top_boundary);
1971 serv_printf("Content-type: %s", att->content_type);
1972 serv_printf("Content-disposition: attachment; filename=\"%s\"", att->filename);
1973 serv_puts("Content-transfer-encoding: base64");
1975 serv_write(encoded, encoded_strlen);
1980 serv_printf("--%s--", top_boundary);
1988 * Post message (or don't post message)
1990 * Note regarding the "dont_post" variable:
1991 * A random value (actually, it's just a timestamp) is inserted as a hidden
1992 * field called "postseq" when the display_enter page is generated. This
1993 * value is checked when posting, using the static variable dont_post. If a
1994 * user attempts to post twice using the same dont_post value, the message is
1995 * discarded. This prevents the accidental double-saving of the same message
1996 * if the user happens to click the browser "back" button.
1998 void post_message(void)
2001 StrBuf *encoded_subject = NULL;
2002 static long dont_post = (-1L);
2003 struct wc_attachment *att, *aptr;
2004 int is_anonymous = 0;
2005 const StrBuf *display_name = NULL;
2006 struct wcsession *WCC = WC;
2008 if (havebstr("force_room")) {
2009 gotoroom(bstr("force_room"));
2012 if (havebstr("display_name")) {
2013 display_name = sbstr("display_name");
2014 if (!strcmp(ChrPtr(display_name), "__ANONYMOUS__")) {
2015 display_name = NULL;
2020 if (WCC->upload_length > 0) {
2022 lprintf(9, "%s:%d: we are uploading %d bytes\n", __FILE__, __LINE__, WCC->upload_length);
2023 /** There's an attachment. Save it to this struct... */
2024 att = malloc(sizeof(struct wc_attachment));
2025 memset(att, 0, sizeof(struct wc_attachment));
2026 att->length = WCC->upload_length;
2027 strcpy(att->content_type, WCC->upload_content_type);
2028 strcpy(att->filename, WCC->upload_filename);
2031 /** And add it to the list. */
2032 if (WCC->first_attachment == NULL) {
2033 WCC->first_attachment = att;
2036 aptr = WCC->first_attachment;
2037 while (aptr->next != NULL) aptr = aptr->next;
2042 * Mozilla sends a simple filename, which is what we want,
2043 * but Satan's Browser sends an entire pathname. Reduce
2044 * the path to just a filename if we need to.
2046 while (num_tokens(att->filename, '/') > 1) {
2047 remove_token(att->filename, 0, '/');
2049 while (num_tokens(att->filename, '\\') > 1) {
2050 remove_token(att->filename, 0, '\\');
2054 * Transfer control of this memory from the upload struct
2055 * to the attachment struct.
2057 att->data = WCC->upload;
2058 WCC->upload_length = 0;
2064 if (havebstr("cancel_button")) {
2065 sprintf(WCC->ImportantMessage,
2066 _("Cancelled. Message was not posted."));
2067 } else if (havebstr("attach_button")) {
2070 } else if (lbstr("postseq") == dont_post) {
2071 sprintf(WCC->ImportantMessage,
2072 _("Automatically cancelled because you have already "
2073 "saved this message."));
2075 const char CMD[] = "ENT0 1|%s|%d|4|%s|%s||%s|%s|%s|%s|%s";
2076 const StrBuf *Recp = NULL;
2077 const StrBuf *Cc = NULL;
2078 const StrBuf *Bcc = NULL;
2079 const StrBuf *Wikipage = NULL;
2080 const StrBuf *my_email_addr = NULL;
2081 StrBuf *CmdBuf = NULL;;
2082 StrBuf *references = NULL;
2084 if (havebstr("references"))
2086 const StrBuf *ref = sbstr("references");
2087 references = NewStrBufPlain(ChrPtr(ref), StrLength(ref));
2088 lprintf(9, "Converting: %s\n", ChrPtr(references));
2089 StrBufReplaceChars(references, '|', '!');
2090 lprintf(9, "Converted: %s\n", ChrPtr(references));
2092 if (havebstr("subject")) {
2095 * make enough room for the encoded string;
2096 * plus the QP header
2098 Subj = sbstr("subject");
2100 StrBufRFC2047encode(&encoded_subject, Subj);
2102 Recp = sbstr("recp");
2105 Wikipage = sbstr("wikipage");
2106 my_email_addr = sbstr("my_email_addr");
2108 CmdBuf = NewStrBufPlain(NULL,
2111 StrLength(encoded_subject) +
2114 StrLength(Wikipage) +
2115 StrLength(my_email_addr) +
2116 StrLength(references));
2118 StrBufPrintf(CmdBuf,
2122 ChrPtr(encoded_subject),
2123 ChrPtr(display_name),
2127 ChrPtr(my_email_addr),
2128 ChrPtr(references));
2129 FreeStrBuf(&references);
2131 lprintf(9, "%s\n", CmdBuf);
2132 serv_puts(ChrPtr(CmdBuf));
2133 serv_getln(buf, sizeof buf);
2134 FreeStrBuf(&CmdBuf);
2135 FreeStrBuf(&encoded_subject);
2136 if (buf[0] == '4') {
2137 post_mime_to_server();
2138 if ( (havebstr("recp"))
2139 || (havebstr("cc" ))
2140 || (havebstr("bcc" ))
2142 sprintf(WCC->ImportantMessage, _("Message has been sent.\n"));
2145 sprintf(WC->ImportantMessage, _("Message has been posted.\n"));
2147 dont_post = lbstr("postseq");
2149 lprintf(9, "%s:%d: server post error: %s\n", __FILE__, __LINE__, buf);
2150 sprintf(WC->ImportantMessage, "%s", &buf[4]);
2156 free_attachments(WCC);
2159 * We may have been supplied with instructions regarding the location
2160 * to which we must return after posting. If found, go there.
2162 if (havebstr("return_to")) {
2163 http_redirect(bstr("return_to"));
2166 * If we were editing a page in a wiki room, go to that page now.
2168 else if (havebstr("wikipage")) {
2169 snprintf(buf, sizeof buf, "wiki?page=%s", bstr("wikipage"));
2173 * Otherwise, just go to the "read messages" loop.
2176 readloop("readnew");
2184 * \brief display the message entry screen
2186 void display_enter(void)
2191 const StrBuf *display_name = NULL;
2192 struct wc_attachment *att;
2193 int recipient_required = 0;
2194 int subject_required = 0;
2195 int recipient_bad = 0;
2196 int is_anonymous = 0;
2197 long existing_page = (-1L);
2198 struct wcsession *WCC = WC;
2202 if (havebstr("force_room")) {
2203 gotoroom(bstr("force_room"));
2206 display_name = sbstr("display_name");
2207 if (!strcmp(ChrPtr(display_name), "__ANONYMOUS__")) {
2208 display_name = NULL;
2212 /** First test to see whether this is a room that requires recipients to be entered */
2213 serv_puts("ENT0 0");
2214 serv_getln(buf, sizeof buf);
2216 if (!strncmp(buf, "570", 3)) { /** 570 means that we need a recipient here */
2217 recipient_required = 1;
2219 else if (buf[0] != '2') { /** Any other error means that we cannot continue */
2220 sprintf(WCC->ImportantMessage, "%s", &buf[4]);
2221 readloop("readnew");
2225 /* Is the server strongly recommending that the user enter a message subject? */
2226 if ((buf[3] != '\0') && (buf[4] != '\0')) {
2227 subject_required = extract_int(&buf[4], 1);
2231 * Are we perhaps in an address book view? If so, then an "enter
2232 * message" command really means "add new entry."
2234 if (WCC->wc_default_view == VIEW_ADDRESSBOOK) {
2235 do_edit_vcard(-1, "", "", WCC->wc_roomname);
2240 * Are we perhaps in a calendar room? If so, then an "enter
2241 * message" command really means "add new calendar item."
2243 if (WCC->wc_default_view == VIEW_CALENDAR) {
2244 display_edit_event();
2249 * Are we perhaps in a tasks view? If so, then an "enter
2250 * message" command really means "add new task."
2252 if (WCC->wc_default_view == VIEW_TASKS) {
2253 display_edit_task();
2258 * Otherwise proceed normally.
2259 * Do a custom room banner with no navbar...
2261 output_headers(1, 1, 2, 0, 0, 0);
2262 wprintf("<div id=\"banner\">\n");
2263 embed_room_banner(NULL, navbar_none);
2264 wprintf("</div>\n");
2265 wprintf("<div id=\"content\">\n"
2266 "<div class=\"fix_scrollbar_bug message \">");
2268 /* Now check our actual recipients if there are any */
2269 if (recipient_required) {
2270 const StrBuf *Recp = NULL;
2271 const StrBuf *Cc = NULL;
2272 const StrBuf *Bcc = NULL;
2273 const StrBuf *Wikipage = NULL;
2274 StrBuf *CmdBuf = NULL;;
2275 const char CMD[] = "ENT0 0|%s|%d|0||%s||%s|%s|%s";
2277 Recp = sbstr("recp");
2280 Wikipage = sbstr("wikipage");
2282 CmdBuf = NewStrBufPlain(NULL,
2285 StrLength(display_name) +
2288 StrLength(Wikipage));
2290 StrBufPrintf(CmdBuf,
2294 ChrPtr(display_name),
2298 serv_puts(ChrPtr(CmdBuf));
2299 serv_getln(buf, sizeof buf);
2300 FreeStrBuf(&CmdBuf);
2302 if (!strncmp(buf, "570", 3)) { /** 570 means we have an invalid recipient listed */
2303 if (havebstr("recp") &&
2309 else if (buf[0] != '2') { /** Any other error means that we cannot continue */
2310 wprintf("<em>%s</em><br />\n", &buf[4]);/// -> important message
2315 /** If we got this far, we can display the message entry screen. */
2317 /* begin message entry screen */
2319 "enctype=\"multipart/form-data\" "
2321 "accept-charset=\"UTF-8\" "
2323 "name=\"enterform\""
2325 wprintf("<input type=\"hidden\" name=\"postseq\" value=\"%ld\">\n", now);
2326 if (WCC->wc_view == VIEW_WIKI) {
2327 wprintf("<input type=\"hidden\" name=\"wikipage\" value=\"%s\">\n", bstr("wikipage"));
2329 wprintf("<input type=\"hidden\" name=\"return_to\" value=\"%s\">\n", bstr("return_to"));
2330 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WCC->nonce);
2331 wprintf("<input type=\"hidden\" name=\"force_room\" value=\"");
2332 escputs(WCC->wc_roomname);
2334 wprintf("<input type=\"hidden\" name=\"references\" value=\"");
2335 escputs(bstr("references"));
2338 /** submit or cancel buttons */
2339 wprintf("<p class=\"send_edit_msg\">");
2340 wprintf("<input type=\"submit\" name=\"send_button\" value=\"");
2341 if (recipient_required) {
2342 wprintf(_("Send message"));
2344 wprintf(_("Post message"));
2347 "<input type=\"submit\" name=\"cancel_button\" value=\"%s\">\n", _("Cancel"));
2352 wprintf("<img src=\"static/newmess3_24x.gif\" class=\"imgedit\">");
2353 wprintf(" "); /** header bar */
2354 webcit_fmt_date(buf, now, 0);
2356 wprintf("\n"); /** header bar */
2358 wprintf("<table width=\"100%%\" class=\"edit_msg_table\">");
2360 wprintf("<th><label for=\"from_id\" > ");
2361 wprintf(_(" <I>from</I> "));
2362 wprintf("</label></th>");
2364 wprintf("<td colspan=\"2\">");
2366 /* Allow the user to select any of his valid screen names */
2368 wprintf("<select name=\"display_name\" size=1 id=\"from_id\">\n");
2371 serv_getln(buf, sizeof buf);
2372 if (buf[0] == '1') {
2373 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
2374 wprintf("<option %s value=\"",
2375 ((!strcasecmp(bstr("display_name"), buf)) ? "selected" : "")
2380 wprintf("</option>\n");
2384 if (WCC->room_flags & QR_ANONOPT) {
2385 wprintf("<option %s value=\"__ANONYMOUS__\">%s</option>\n",
2386 ((!strcasecmp(bstr("__ANONYMOUS__"), WCC->wc_fullname)) ? "selected" : ""),
2391 wprintf("</select>\n");
2393 /* If this is an email (not a post), allow the user to select any of his
2394 * valid email addresses.
2396 if (recipient_required) {
2398 serv_getln(buf, sizeof buf);
2399 if (buf[0] == '1') {
2400 wprintf("<select name=\"my_email_addr\" size=1>\n");
2401 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
2402 wprintf("<option value=\"");
2406 wprintf("></option>\n");
2408 wprintf("</select>\n");
2412 wprintf(_(" <I>in</I> "));
2413 escputs(WCC->wc_roomname);
2415 wprintf("</td></tr>");
2417 if (recipient_required) {
2421 wprintf("<tr><th><label for=\"recp_id\"> ");
2423 wprintf("</label></th>"
2424 "<td><input autocomplete=\"off\" type=\"text\" name=\"recp\" id=\"recp_id\" value=\"");
2425 ccraw = xbstr("recp", &len);
2426 copy = (char*) malloc(len * 2 + 1);
2427 memcpy(copy, ccraw, len + 1);
2428 utf8ify_rfc822_string(copy);
2431 wprintf("\" size=45 maxlength=1000 />");
2432 wprintf("<div class=\"auto_complete\" id=\"recp_name_choices\"></div>");
2433 wprintf("</td><td rowspan=\"3\" align=\"left\" valign=\"top\">");
2435 /** Pop open an address book -- begin **/
2437 "<a href=\"javascript:PopOpenAddressBook('recp_id|%s|cc_id|%s|bcc_id|%s');\" "
2439 "<img align=middle border=0 width=24 height=24 src=\"static/viewcontacts_24x.gif\">"
2441 _("To:"), _("CC:"), _("BCC:"),
2442 _("Contacts"), _("Contacts")
2444 /** Pop open an address book -- end **/
2446 wprintf("</td></tr>");
2448 wprintf("<tr><th><label for=\"cc_id\"> ");
2450 wprintf("</label></th>"
2451 "<td><input autocomplete=\"off\" type=\"text\" name=\"cc\" id=\"cc_id\" value=\"");
2452 ccraw = xbstr("cc", &len);
2453 copy = (char*) malloc(len * 2 + 1);
2454 memcpy(copy, ccraw, len + 1);
2455 utf8ify_rfc822_string(copy);
2458 wprintf("\" size=45 maxlength=1000 />");
2459 wprintf("<div class=\"auto_complete\" id=\"cc_name_choices\"></div>");
2460 wprintf("</td></tr>");
2462 wprintf("<tr><th><label for=\"bcc_id\"> ");
2464 wprintf("</label></th>"
2465 "<td><input autocomplete=\"off\" type=\"text\" name=\"bcc\" id=\"bcc_id\" value=\"");
2466 ccraw = xbstr("bcc", &len);
2467 copy = (char*) malloc(len * 2 + 1);
2468 memcpy(copy, ccraw, len + 1);
2469 utf8ify_rfc822_string(copy);
2472 wprintf("\" size=45 maxlength=1000 />");
2473 wprintf("<div class=\"auto_complete\" id=\"bcc_name_choices\"></div>");
2474 wprintf("</td></tr>");
2476 /** Initialize the autocomplete ajax helpers (found in wclib.js) */
2477 wprintf("<script type=\"text/javascript\"> \n"
2478 " activate_entmsg_autocompleters(); \n"
2484 wprintf("<tr><th><label for=\"subject_id\" > ");
2485 if (recipient_required || subject_required) {
2486 wprintf(_("Subject:"));
2489 wprintf(_("Subject (optional):"));
2491 wprintf("</label></th>"
2492 "<td colspan=\"2\">"
2493 "<input type=\"text\" name=\"subject\" id=\"subject_id\" value=\"");
2494 escputs(bstr("subject"));
2495 wprintf("\" size=45 maxlength=70>\n");
2496 wprintf("</td></tr>");
2498 wprintf("<tr><td colspan=\"3\">\n");
2500 wprintf("<textarea name=\"msgtext\" cols=\"80\" rows=\"15\">");
2502 /** If we're continuing from a previous edit, put our partially-composed message back... */
2503 msgescputs(bstr("msgtext"));
2505 /* If we're forwarding a message, insert it here... */
2506 if (lbstr("fwdquote") > 0L) {
2507 wprintf("<br><div align=center><i>");
2508 wprintf(_("--- forwarded message ---"));
2509 wprintf("</i></div><br>");
2510 pullquote_message(lbstr("fwdquote"), 1, 1);
2513 /** If we're replying quoted, insert the quote here... */
2514 else if (lbstr("replyquote") > 0L) {
2517 pullquote_message(lbstr("replyquote"), 0, 1);
2518 wprintf("</blockquote><br>");
2521 /** If we're editing a wiki page, insert the existing page here... */
2522 else if (WCC->wc_view == VIEW_WIKI) {
2523 safestrncpy(buf, bstr("wikipage"), sizeof buf);
2524 str_wiki_index(buf);
2525 existing_page = locate_message_by_uid(buf);
2526 if (existing_page >= 0L) {
2527 pullquote_message(existing_page, 1, 0);
2531 /** Insert our signature if appropriate... */
2532 if ( (WCC->is_mailbox) && !yesbstr("sig_inserted") ) {
2534 get_pref_yesno("use_sig", &UseSig, 0);
2537 const char *sig, *esig;
2539 get_preference("signature", &ebuf);
2541 StrBufEUid_unescapize(Sig, ebuf);
2543 esig = sig + StrLength(Sig);
2544 wprintf("<br>--<br>");
2545 while (sig <= esig) {
2549 else if (*sig == '<') {
2552 else if (*sig == '>') {
2555 else if (*sig == '&') {
2558 else if (*sig == '\"') {
2561 else if (*sig == '\'') {
2564 else /* since we're utf 8, is this a good idea? if (isprint(*sig))*/ {
2565 wprintf("%c", *sig);
2573 wprintf("</textarea>\n");
2575 /** Make sure we only insert our signature once */
2576 /** We don't care if it was there or not before, it needs to be there now. */
2577 wprintf("<input type=\"hidden\" name=\"sig_inserted\" value=\"yes\">\n");
2580 * The following template embeds the TinyMCE richedit control, and automatically
2581 * transforms the textarea into a richedit textarea.
2583 do_template("richedit", NULL);
2585 /** Enumerate any attachments which are already in place... */
2586 wprintf("<div class=\"attachment buttons\"><img src=\"static/diskette_24x.gif\" class=\"imgedit\" > ");
2587 wprintf(_("Attachments:"));
2589 wprintf("<select name=\"which_attachment\" size=1>");
2590 for (att = WCC->first_attachment; att != NULL; att = att->next) {
2591 wprintf("<option value=\"");
2592 urlescputs(att->filename);
2594 escputs(att->filename);
2595 /* wprintf(" (%s, %d bytes)",att->content_type,att->length); */
2596 wprintf("</option>\n");
2598 wprintf("</select>");
2600 /** Now offer the ability to attach additional files... */
2601 wprintf(" ");
2602 wprintf(_("Attach file:"));
2603 wprintf(" <input name=\"attachfile\" class=\"attachfile\" "
2604 "size=16 type=\"file\">\n "
2605 "<input type=\"submit\" name=\"attach_button\" value=\"%s\">\n", _("Add"));
2606 wprintf("</div>"); /* End of "attachment buttons" div */
2609 wprintf("</td></tr></table>");
2611 wprintf("</form>\n");
2612 wprintf("</div>\n"); /* end of "fix_scrollbar_bug" div */
2614 /* NOTE: address_book_popup() will close the "content" div. Don't close it here. */
2615 DONE: address_book_popup();
2621 * \brief delete a message
2623 void delete_msg(void)
2628 msgid = lbstr("msgid");
2630 if (WC->wc_is_trash) { /** Delete from Trash is a real delete */
2631 serv_printf("DELE %ld", msgid);
2633 else { /** Otherwise move it to Trash */
2634 serv_printf("MOVE %ld|_TRASH_|0", msgid);
2637 serv_getln(buf, sizeof buf);
2638 sprintf(WC->ImportantMessage, "%s", &buf[4]);
2640 readloop("readnew");
2645 * \brief move a message to another folder
2652 msgid = lbstr("msgid");
2654 if (havebstr("move_button")) {
2655 sprintf(buf, "MOVE %ld|%s", msgid, bstr("target_room"));
2657 serv_getln(buf, sizeof buf);
2658 sprintf(WC->ImportantMessage, "%s", &buf[4]);
2660 sprintf(WC->ImportantMessage, (_("The message was not moved.")));
2663 readloop("readnew");
2671 * Confirm move of a message
2673 void confirm_move_msg(void)
2679 msgid = lbstr("msgid");
2682 output_headers(1, 1, 2, 0, 0, 0);
2683 wprintf("<div id=\"banner\">\n");
2685 wprintf(_("Confirm move of message"));
2687 wprintf("</div>\n");
2689 wprintf("<div id=\"content\" class=\"service\">\n");
2691 wprintf("<CENTER>");
2693 wprintf(_("Move this message to:"));
2694 wprintf("<br />\n");
2696 wprintf("<form METHOD=\"POST\" action=\"move_msg\">\n");
2697 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
2698 wprintf("<INPUT TYPE=\"hidden\" NAME=\"msgid\" VALUE=\"%s\">\n", bstr("msgid"));
2700 wprintf("<SELECT NAME=\"target_room\" SIZE=5>\n");
2702 serv_getln(buf, sizeof buf);
2703 if (buf[0] == '1') {
2704 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
2705 extract_token(targ, buf, 0, '|', sizeof targ);
2706 wprintf("<OPTION>");
2711 wprintf("</SELECT>\n");
2712 wprintf("<br />\n");
2714 wprintf("<INPUT TYPE=\"submit\" NAME=\"move_button\" VALUE=\"%s\">", _("Move"));
2716 wprintf("<INPUT TYPE=\"submit\" NAME=\"cancel_button\" VALUE=\"%s\">", _("Cancel"));
2717 wprintf("</form></CENTER>\n");
2719 wprintf("</CENTER>\n");
2723 void readnew(void) { readloop("readnew");}
2724 void readold(void) { readloop("readold");}
2725 void readfwd(void) { readloop("readfwd");}
2726 void headers(void) { readloop("headers");}
2727 void do_search(void) { readloop("do_search");}
2738 WebcitAddUrlHandler(HKEY("readnew"), readnew, 0);
2739 WebcitAddUrlHandler(HKEY("readold"), readold, 0);
2740 WebcitAddUrlHandler(HKEY("readfwd"), readfwd, 0);
2741 WebcitAddUrlHandler(HKEY("headers"), headers, 0);
2742 WebcitAddUrlHandler(HKEY("do_search"), do_search, 0);
2743 WebcitAddUrlHandler(HKEY("display_enter"), display_enter, 0);
2744 WebcitAddUrlHandler(HKEY("post"), post_message, 0);
2745 WebcitAddUrlHandler(HKEY("move_msg"), move_msg, 0);
2746 WebcitAddUrlHandler(HKEY("delete_msg"), delete_msg, 0);
2747 WebcitAddUrlHandler(HKEY("confirm_move_msg"), confirm_move_msg, 0);
2748 WebcitAddUrlHandler(HKEY("msg"), embed_message, NEED_URL|AJAX);
2749 WebcitAddUrlHandler(HKEY("printmsg"), print_message, NEED_URL);
2750 WebcitAddUrlHandler(HKEY("mobilemsg"), mobile_message_view, NEED_URL);
2751 WebcitAddUrlHandler(HKEY("msgheaders"), display_headers, NEED_URL);