- char mime_partnum[256] = "";
- char mime_name[256] = "";
- char mime_filename[256] = "";
- char escaped_mime_filename[256] = "";
- char mime_content_type[256] = "";
- const char *mime_content_type_ptr;
- char mime_charset[256] = "";
- char mime_disposition[256] = "";
- int mime_length;
- struct attach_link *attach_links = NULL;
- int num_attach_links = 0;
- char mime_submessages[256] = "";
- char m_subject[1024] = "";
- char m_cc[1024] = "";
- char from[256] = "";
- char node[256] = "";
- char rfca[256] = "";
- char reply_to[512] = "";
- char reply_all[4096] = "";
- char reply_references[1024] = "";
- char reply_inreplyto[256] = "";
- char now[64] = "";
- int format_type = 0;
- int nhdr = 0;
- int bq = 0;
- int i = 0;
- char vcard_partnum[256] = "";
- char cal_partnum[256] = "";
- char *part_source = NULL;
- char msg4_partnum[32] = "";
-#ifdef HAVE_ICONV
- iconv_t ic = (iconv_t)(-1) ;
- char *ibuf; /**< Buffer of characters to be converted */
- char *obuf; /**< Buffer for converted characters */
- size_t ibuflen; /**< Length of input buffer */
- size_t obuflen; /**< Length of output buffer */
- char *osav; /**< Saved pointer to output buffer */
-#endif
-
- strcpy(mime_content_type, "text/plain");
- strcpy(mime_charset, "us-ascii");
- strcpy(mime_submessages, "");
-
- serv_printf("MSG4 %ld|%s", msgnum, section);
- serv_getln(buf, sizeof buf);
- if (buf[0] != '1') {
- wprintf("<strong>");
- wprintf(_("ERROR:"));
- wprintf("</strong> %s<br />\n", &buf[4]);
- return;
- }
-
- /** begin everythingamundo table */
- if (!printable_view) {
- wprintf("<div class=\"fix_scrollbar_bug message\" ");
- wprintf("onMouseOver=document.getElementById(\"msg%ld\").style.visibility=\"visible\" ", msgnum);
- wprintf("onMouseOut=document.getElementById(\"msg%ld\").style.visibility=\"hidden\" >", msgnum);
- }
-
- /** begin message header table */
- wprintf("<div class=\"message_header\">");
-
- strcpy(m_subject, "");
- strcpy(m_cc, "");
-
- while (serv_getln(buf, sizeof buf), strcasecmp(buf, "text")) {
- if (!strcmp(buf, "000")) {
- wprintf("<i>");
- wprintf(_("unexpected end of message"));
- wprintf(" (1)</i><br /><br />\n");
- wprintf("</div>\n");
- return;
- }
- if (!strncasecmp(buf, "nhdr=yes", 8))
- nhdr = 1;
- if (nhdr == 1)
- buf[0] = '_';
- if (!strncasecmp(buf, "type=", 5))
- format_type = atoi(&buf[5]);
- if (!strncasecmp(buf, "from=", 5)) {
- strcpy(from, &buf[5]);
- wprintf(_("from "));
- wprintf("<a href=\"showuser?who=");
- utf8ify_rfc822_string(from);
- urlescputs(from);
- wprintf("\">");
- escputs(from);
- wprintf("</a> ");
- }
- if (!strncasecmp(buf, "subj=", 5)) {
- safestrncpy(m_subject, &buf[5], sizeof m_subject);
- }
- if (!strncasecmp(buf, "msgn=", 5)) {
- safestrncpy(reply_inreplyto, &buf[5], sizeof reply_inreplyto);
- }
- if (!strncasecmp(buf, "wefw=", 5)) {
- safestrncpy(reply_references, &buf[5], sizeof reply_references);
- }
- if (!strncasecmp(buf, "cccc=", 5)) {
- int len;
- safestrncpy(m_cc, &buf[5], sizeof m_cc);
- if (!IsEmptyStr(reply_all)) {
- strcat(reply_all, ", ");
- }
- len = strlen(reply_all);
- safestrncpy(&reply_all[len], &buf[5],
- (sizeof reply_all - len) );
- }
- if ((!strncasecmp(buf, "hnod=", 5))
- && (strcasecmp(&buf[5], serv_info.serv_humannode))) {
- wprintf("(%s) ", &buf[5]);
- }
- if ((!strncasecmp(buf, "room=", 5))
- && (strcasecmp(&buf[5], WC->wc_roomname))
- && (!IsEmptyStr(&buf[5])) ) {
- wprintf(_("in "));
- wprintf("%s> ", &buf[5]);
- }
- if (!strncasecmp(buf, "rfca=", 5)) {
- strcpy(rfca, &buf[5]);
- wprintf("<");
- escputs(rfca);
- wprintf("> ");
- }
-
- if (!strncasecmp(buf, "node=", 5)) {
- strcpy(node, &buf[5]);
- if ( ((WC->room_flags & QR_NETWORK)
- || ((strcasecmp(&buf[5], serv_info.serv_nodename)
- && (strcasecmp(&buf[5], serv_info.serv_fqdn)))))
- && (IsEmptyStr(rfca))
- ) {
- wprintf("@%s ", &buf[5]);
- }
- }
- if (!strncasecmp(buf, "rcpt=", 5)) {
- int len;
- wprintf(_("to "));
- if (!IsEmptyStr(reply_all)) {
- strcat(reply_all, ", ");
- }
- len = strlen(reply_all);
- safestrncpy(&reply_all[len], &buf[5],
- (sizeof reply_all - len) );
- utf8ify_rfc822_string(&buf[5]);
- escputs(&buf[5]);
- wprintf(" ");
- }
- if (!strncasecmp(buf, "time=", 5)) {
- webcit_fmt_date(now, atol(&buf[5]), 0);
- wprintf("<span>");
- wprintf("%s ", now);
- wprintf("</span>");
- }
-
- if (!strncasecmp(buf, "part=", 5)) {
- extract_token(mime_name, &buf[5], 0, '|', sizeof mime_filename);
- extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
- extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
- extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
- extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
- mime_length = extract_int(&buf[5], 5);
-
- striplt(mime_name);
- striplt(mime_filename);
- if ( (IsEmptyStr(mime_filename)) && (!IsEmptyStr(mime_name)) ) {
- strcpy(mime_filename, mime_name);
- }
-
- if (!strcasecmp(mime_content_type, "message/rfc822")) {
- if (!IsEmptyStr(mime_submessages)) {
- strcat(mime_submessages, "|");
- }
- strcat(mime_submessages, mime_partnum);
- }
- else if ((!strcasecmp(mime_disposition, "inline"))
- && (!strncasecmp(mime_content_type, "image/", 6)) ){
- ++num_attach_links;
- attach_links = realloc(attach_links,
- (num_attach_links*sizeof(struct attach_link)));
- safestrncpy(attach_links[num_attach_links-1].partnum, mime_partnum, 32);
- snprintf(attach_links[num_attach_links-1].html, 1024,
- "<img src=\"mimepart/%ld/%s/%s\">",
- msgnum, mime_partnum, mime_filename);
- }
- else if ( ( (!strcasecmp(mime_disposition, "attachment"))
- || (!strcasecmp(mime_disposition, "inline"))
- || (!strcasecmp(mime_disposition, ""))
- ) && (!IsEmptyStr(mime_content_type))
- ) {
- ++num_attach_links;
- attach_links = realloc(attach_links,
- (num_attach_links*sizeof(struct attach_link)));
- safestrncpy(attach_links[num_attach_links-1].partnum, mime_partnum, 32);
- utf8ify_rfc822_string(mime_filename);
-
- mime_content_type_ptr = mime_content_type;
- if (strcasecmp(mime_content_type, "application/octet-stream") == 0) {
- mime_content_type_ptr = GuessMimeByFilename(mime_filename,
- strlen(mime_filename));
- }
- urlesc(escaped_mime_filename, 265, mime_filename);
- snprintf(attach_links[num_attach_links-1].html, 1024,
- "<img src=\"display_mime_icon?type=%s\" "
- "border=0 align=middle>\n"
- "%s (%s, %d bytes) [ "
- "<a href=\"mimepart/%ld/%s/%s\""
- "target=\"wc.%ld.%s\">%s</a>"
- " | "
- "<a href=\"mimepart_download/%ld/%s/%s\">%s</a>"
- " ]<br />\n",
- mime_content_type_ptr,
- mime_filename,
- mime_content_type, mime_length,
- msgnum, mime_partnum, escaped_mime_filename,
- msgnum, mime_partnum,
- _("View"),
- msgnum, mime_partnum, escaped_mime_filename,
- _("Download")
- );
- }
-
- /** begin handler prep ***/
- if ( (!strcasecmp(mime_content_type, "text/x-vcard"))
- || (!strcasecmp(mime_content_type, "text/vcard")) ) {
- strcpy(vcard_partnum, mime_partnum);
- }
-
- if ( (!strcasecmp(mime_content_type, "text/calendar"))
- || (!strcasecmp(mime_content_type, "application/ics")) ) {
- strcpy(cal_partnum, mime_partnum);
- }
-
- /** end handler prep ***/
-
- }
-
- }
-
- /* Trim down excessively long lists of thread references. We eliminate the
- * second one in the list so that the thread root remains intact.
- */
- int rrtok = num_tokens(reply_references, '|');
- int rrlen = strlen(reply_references);
- if ( ((rrtok >= 3) && (rrlen > 900)) || (rrtok > 10) ) {
- remove_token(reply_references, 1, '|');
- }
-
- /* Generate a reply-to address */
- if (!IsEmptyStr(rfca)) {
- if (!IsEmptyStr(from)) {
- snprintf(reply_to, sizeof(reply_to), "%s <%s>", from, rfca);
- }
- else {
- strcpy(reply_to, rfca);
- }
- }
- else {
- if ((!IsEmptyStr(node))
- && (strcasecmp(node, serv_info.serv_nodename))
- && (strcasecmp(node, serv_info.serv_humannode)) ) {
- snprintf(reply_to, sizeof(reply_to), "%s @ %s",
- from, node);
- }
- else {
- snprintf(reply_to, sizeof(reply_to), "%s", from);
- }
- }
-
- if (nhdr == 1) {
- wprintf("****");
- }
-
- utf8ify_rfc822_string(m_cc);
- utf8ify_rfc822_string(m_subject);
-
- /** start msg buttons */
-
- if (!printable_view) {
- wprintf("<p id=\"msg%ld\" class=\"msgbuttons\" >\n",msgnum);
-
- /* Reply */
- if ( (WC->wc_view == VIEW_MAILBOX) || (WC->wc_view == VIEW_BBS) ) {
- wprintf("<a href=\"display_enter");
- if (WC->is_mailbox) {
- wprintf("?replyquote=%ld", msgnum);
- }
- wprintf("?recp=");
- urlescputs(reply_to);
- if (!IsEmptyStr(m_subject)) {
- wprintf("?subject=");
- if (strncasecmp(m_subject, "Re:", 3)) wprintf("Re:%20");
- urlescputs(m_subject);
- }
- wprintf("?references=");
- if (!IsEmptyStr(reply_references)) {
- urlescputs(reply_references);
- urlescputs("|");
- }
- urlescputs(reply_inreplyto);
- wprintf("\"><span>[</span>%s<span>]</span></a> ", _("Reply"));
- }
-
- /* ReplyQuoted */
- if ( (WC->wc_view == VIEW_MAILBOX) || (WC->wc_view == VIEW_BBS) ) {
- if (!WC->is_mailbox) {
- wprintf("<a href=\"display_enter");
- wprintf("?replyquote=%ld", msgnum);
- wprintf("?recp=");
- urlescputs(reply_to);
- if (!IsEmptyStr(m_subject)) {
- wprintf("?subject=");
- if (strncasecmp(m_subject, "Re:", 3)) wprintf("Re:%20");
- urlescputs(m_subject);
- }
- wprintf("?references=");
- if (!IsEmptyStr(reply_references)) {
- urlescputs(reply_references);
- urlescputs("|");
- }
- urlescputs(reply_inreplyto);
- wprintf("\"><span>[</span>%s<span>]</span></a> ", _("ReplyQuoted"));
- }
- }
-
- /* ReplyAll */
- if (WC->wc_view == VIEW_MAILBOX) {
- wprintf("<a href=\"display_enter");
- wprintf("?replyquote=%ld", msgnum);
- wprintf("?recp=");
- urlescputs(reply_to);
- wprintf("?cc=");
- urlescputs(reply_all);
- if (!IsEmptyStr(m_subject)) {
- wprintf("?subject=");
- if (strncasecmp(m_subject, "Re:", 3)) wprintf("Re:%20");
- urlescputs(m_subject);
- }
- wprintf("?references=");
- if (!IsEmptyStr(reply_references)) {
- urlescputs(reply_references);
- urlescputs("|");
- }
- urlescputs(reply_inreplyto);
- wprintf("\"><span>[</span>%s<span>]</span></a> ", _("ReplyAll"));
- }
-
- /* Forward */
- if (WC->wc_view == VIEW_MAILBOX) {
- wprintf("<a href=\"display_enter?fwdquote=%ld?subject=", msgnum);
- if (strncasecmp(m_subject, "Fwd:", 4)) wprintf("Fwd:%20");
- urlescputs(m_subject);
- wprintf("\"><span>[</span>%s<span>]</span></a> ", _("Forward"));
- }
-
- /* If this is one of my own rooms, or if I'm an Aide or Room Aide, I can move/delete */
- if ( (WC->is_room_aide) || (WC->is_mailbox) || (WC->room_flags2 & QR2_COLLABDEL) ) {
- /** Move */
- wprintf("<a href=\"confirm_move_msg?msgid=%ld\"><span>[</span>%s<span>]</span></a> ",
- msgnum, _("Move"));
-
- /** Delete */
- wprintf("<a href=\"delete_msg?msgid=%ld\" "
- "onClick=\"return confirm('%s');\">"
- "<span>[</span>%s<span>]</span> "
- "</a> ", msgnum, _("Delete this message?"), _("Delete")
- );
- }
-
- /* Headers */
- wprintf("<a href=\"#\" onClick=\"window.open('msgheaders/%ld', 'headers%ld', 'toolbar=no,location=no,directories=no,copyhistory=no,status=yes,scrollbars=yes,resizable=yes,width=600,height=400'); \" >"
- "<span>[</span>%s<span>]</span></a>", msgnum, msgnum, _("Headers"));
-
-
- /* Print */
- wprintf("<a href=\"#\" onClick=\"window.open('printmsg/%ld', 'print%ld', 'toolbar=no,location=no,directories=no,copyhistory=no,status=yes,scrollbars=yes,resizable=yes,width=600,height=400'); \" >"
- "<span>[</span>%s<span>]</span></a>", msgnum, msgnum, _("Print"));
-
- wprintf("</p>");
-
- }
-
- if (!IsEmptyStr(m_cc)) {
- wprintf("<p>");
- wprintf(_("CC:"));
- wprintf(" ");
- escputs(m_cc);
- wprintf("</p>");
- }
- if (!IsEmptyStr(m_subject)) {
- wprintf("<p class=\"message_subject\">");
- wprintf(_("Subject:"));
- wprintf(" ");
- escputs(m_subject);
- wprintf("</p>");
- }
-
- wprintf("</div>");
-
- /* Begin body */
- wprintf("<div class=\"message_content\">");
-
- /*
- * Learn the content type
- */
- strcpy(mime_content_type, "text/plain");
- while (serv_getln(buf, sizeof buf), (!IsEmptyStr(buf))) {
- if (!strcmp(buf, "000")) {
- /* This is not necessarily an error condition. See bug #226. */
- goto ENDBODY;
- }
- if (!strncasecmp(buf, "X-Citadel-MSG4-Partnum:", 23)) {
- safestrncpy(msg4_partnum, &buf[23], sizeof(msg4_partnum));
- striplt(msg4_partnum);
- }
- if (!strncasecmp(buf, "Content-type:", 13)) {
- int len;
- safestrncpy(mime_content_type, &buf[13], sizeof(mime_content_type));
- striplt(mime_content_type);
- len = strlen(mime_content_type);
- for (i=0; i<len; ++i) {
- if (!strncasecmp(&mime_content_type[i], "charset=", 8)) {
- safestrncpy(mime_charset, &mime_content_type[i+8],
- sizeof mime_charset);
- }
- }
- for (i=0; i<len; ++i) {
- if (mime_content_type[i] == ';') {
- mime_content_type[i] = 0;
- len = i - 1;
- }
- }
- len = strlen(mime_charset);
- for (i=0; i<len; ++i) {
- if (mime_charset[i] == ';') {
- mime_charset[i] = 0;
- len = i - 1;
- }
- }
- }
- }
-
- /* Set up a character set conversion if we need to (and if we can) */
-#ifdef HAVE_ICONV
- if (strchr(mime_charset, ';')) strcpy(strchr(mime_charset, ';'), "");
- if ( (strcasecmp(mime_charset, "us-ascii"))
- && (strcasecmp(mime_charset, "UTF-8"))
- && (strcasecmp(mime_charset, ""))
- ) {
- ic = ctdl_iconv_open("UTF-8", mime_charset);
- if (ic == (iconv_t)(-1) ) {
- lprintf(5, "%s:%d iconv_open(UTF-8, %s) failed: %s\n",
- __FILE__, __LINE__, mime_charset, strerror(errno));
- }
- }
-#endif
-
- /* Messages in legacy Citadel variformat get handled thusly... */
- if (!strcasecmp(mime_content_type, "text/x-citadel-variformat")) {
- fmout("JUSTIFY");
- }
-
- /* Boring old 80-column fixed format text gets handled this way... */
- else if ( (!strcasecmp(mime_content_type, "text/plain"))
- || (!strcasecmp(mime_content_type, "text")) ) {
- buf [0] = '\0';
- while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
- int len;
- len = strlen(buf);
- if ((len > 0) && buf[len-1] == '\n') buf[--len] = 0;
- if ((len > 0) && buf[len-1] == '\r') buf[--len] = 0;
-
-#ifdef HAVE_ICONV
- if (ic != (iconv_t)(-1) ) {
- ibuf = buf;
- ibuflen = strlen(ibuf);
- obuflen = SIZ;
- obuf = (char *) malloc(obuflen);
- osav = obuf;
- iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
- osav[SIZ-obuflen] = 0;
- safestrncpy(buf, osav, sizeof buf);
- free(osav);
- }
-#endif
-
- len = strlen(buf);
- while ((!IsEmptyStr(buf)) && (isspace(buf[len-1])))
- buf[--len] = 0;
- if ((bq == 0) &&
- ((!strncmp(buf, ">", 1)) || (!strncmp(buf, " >", 2)) )) {
- wprintf("<blockquote>");
- bq = 1;
- } else if ((bq == 1) &&
- (strncmp(buf, ">", 1)) && (strncmp(buf, " >", 2)) ) {
- wprintf("</blockquote>");
- bq = 0;
- }
- wprintf("<tt>");
- url(buf);
- escputs(buf);
- wprintf("</tt><br />\n");
- }
- wprintf("</i><br />");
- }
-
- else /** HTML is fun, but we've got to strip it first */
- if (!strcasecmp(mime_content_type, "text/html")) {
- output_html(mime_charset, (WC->wc_view == VIEW_WIKI ? 1 : 0));
- }
-
- /** Unknown weirdness */
- else {
- wprintf(_("I don't know how to display %s"), mime_content_type);
- wprintf("<br />\n", mime_content_type);
- while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { }
- }
-
-ENDBODY: /* If there are attached submessages, display them now... */
-
- if ( (!IsEmptyStr(mime_submessages)) && (!section[0]) ) {
- for (i=0; i<num_tokens(mime_submessages, '|'); ++i) {
- extract_token(buf, mime_submessages, i, '|', sizeof buf);
- /** use printable_view to suppress buttons */
- wprintf("<blockquote>");
- read_message(msgnum, 1, buf);
- wprintf("</blockquote>");
- }
- }
-
-
- /** Afterwards, offer links to download attachments 'n' such */
- if ( (num_attach_links > 0) && (!section[0]) ) {
- for (i=0; i<num_attach_links; ++i) {
- if (strcasecmp(attach_links[i].partnum, msg4_partnum)) {
- wprintf("%s", attach_links[i].html);
- }
- }
- }
-
- /** Handler for vCard parts */
- if (!IsEmptyStr(vcard_partnum)) {
- part_source = load_mimepart(msgnum, vcard_partnum);
- if (part_source != NULL) {
-
- /** If it's my vCard I can edit it */
- if ( (!strcasecmp(WC->wc_roomname, USERCONFIGROOM))
- || (!strcasecmp(&WC->wc_roomname[11], USERCONFIGROOM))
- || (WC->wc_view == VIEW_ADDRESSBOOK)
- ) {
- wprintf("<a href=\"edit_vcard?"
- "msgnum=%ld?partnum=%s\">",
- msgnum, vcard_partnum);
- wprintf("[%s]</a>", _("edit"));
- }
-
- /** In all cases, display the full card */
- display_vcard(part_source, 0, 1, NULL);
- }
- }
-
- /** Handler for calendar parts */
- if (!IsEmptyStr(cal_partnum)) {
- part_source = load_mimepart(msgnum, cal_partnum);
- if (part_source != NULL) {
- cal_process_attachment(part_source,
- msgnum, cal_partnum);
- }
- }
-
- if (part_source) {
- free(part_source);
- part_source = NULL;
- }
-
- wprintf("</div>\n");
-
- /** end everythingamundo table */
- if (!printable_view) {
- wprintf("</div>\n");
- }
-
- if (num_attach_links > 0) {
- free(attach_links);
- }
-
-#ifdef HAVE_ICONV
- if (ic != (iconv_t)(-1) ) {
- iconv_close(ic);
- }
-#endif
-}
-
-
-
-/**
- * \brief Unadorned HTML output of an individual message, suitable
- * for placing in a hidden iframe, for printing, or whatever
- *
- * \param msgnum_as_string Message number, as a string instead of as a long int
- */
-void embed_message(char *msgnum_as_string) {
- long msgnum = 0L;
-
- msgnum = atol(msgnum_as_string);
- begin_ajax_response();
- read_message(msgnum, 0, "");
- end_ajax_response();
-}
-
-
-/**
- * \brief Printable view of a message
- *
- * \param msgnum_as_string Message number, as a string instead of as a long int
- */
-void print_message(char *msgnum_as_string) {
- long msgnum = 0L;
-
- msgnum = atol(msgnum_as_string);
- output_headers(0, 0, 0, 0, 0, 0);
-
- wprintf("Content-type: text/html\r\n"
- "Server: %s\r\n"
- "Connection: close\r\n",
- PACKAGE_STRING);
- begin_burst();
-
- wprintf("\r\n\r\n<html>\n"
- "<head><title>Printable view</title></head>\n"
- "<body onLoad=\" window.print(); window.close(); \">\n"
- );
-
- read_message(msgnum, 1, "");
-
- wprintf("\n</body></html>\n\n");
- wDumpContent(0);
-}
-
-
-
-/**
- * \brief Display a message's headers
- *
- * \param msgnum_as_string Message number, as a string instead of as a long int
- */
-void display_headers(char *msgnum_as_string) {
- long msgnum = 0L;
- char buf[1024];
-
- msgnum = atol(msgnum_as_string);
- output_headers(0, 0, 0, 0, 0, 0);
-
- wprintf("Content-type: text/plain\r\n"
- "Server: %s\r\n"
- "Connection: close\r\n",
- PACKAGE_STRING);
- begin_burst();
-
- serv_printf("MSG2 %ld|3", msgnum);
- serv_getln(buf, sizeof buf);
- if (buf[0] == '1') {
- while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
- wprintf("%s\n", buf);
- }
- }
-
- wDumpContent(0);
-}
-
-
-
-/**
- * \brief Read message in simple, JavaScript-embeddable form for 'forward'
- * or 'reply quoted' operations.
- *
- * NOTE: it is VITALLY IMPORTANT that we output no single-quotes or linebreaks
- * in this function. Doing so would throw a JavaScript error in the
- * 'supplied text' argument to the editor.
- *
- * \param msgnum Message number of the message we want to quote
- * \param forward_attachments Nonzero if we want attachments to be forwarded
- */
-void pullquote_message(long msgnum, int forward_attachments, int include_headers) {
- char buf[SIZ];
- char mime_partnum[256];
- char mime_filename[256];
- char mime_content_type[256];
- char mime_charset[256];
- char mime_disposition[256];
- int mime_length;
- char *attachments = NULL;
- char *ptr = NULL;
- int num_attachments = 0;
- struct wc_attachment *att, *aptr;
- char m_subject[1024];
- char from[256];
- char node[256];
- char rfca[256];
- char to[256];
- char reply_to[512];
- char now[256];
- int format_type = 0;
- int nhdr = 0;
- int bq = 0;
- int i = 0;
-#ifdef HAVE_ICONV
- iconv_t ic = (iconv_t)(-1) ;
- char *ibuf; /**< Buffer of characters to be converted */
- char *obuf; /**< Buffer for converted characters */
- size_t ibuflen; /**< Length of input buffer */
- size_t obuflen; /**< Length of output buffer */
- char *osav; /**< Saved pointer to output buffer */
-#endif
-
- strcpy(from, "");
- strcpy(node, "");
- strcpy(rfca, "");
- strcpy(reply_to, "");
- strcpy(mime_content_type, "text/plain");
- strcpy(mime_charset, "us-ascii");
-
- serv_printf("MSG4 %ld", msgnum);
- serv_getln(buf, sizeof buf);
- if (buf[0] != '1') {
- wprintf(_("ERROR:"));
- wprintf("%s<br />", &buf[4]);
- return;
- }
-
- strcpy(m_subject, "");
-
- while (serv_getln(buf, sizeof buf), strcasecmp(buf, "text")) {
- if (!strcmp(buf, "000")) {
- wprintf("%s (3)", _("unexpected end of message"));
- return;
- }
- if (include_headers) {
- if (!strncasecmp(buf, "nhdr=yes", 8))
- nhdr = 1;
- if (nhdr == 1)
- buf[0] = '_';
- if (!strncasecmp(buf, "type=", 5))
- format_type = atoi(&buf[5]);
- if (!strncasecmp(buf, "from=", 5)) {
- strcpy(from, &buf[5]);
- wprintf(_("from "));
- utf8ify_rfc822_string(from);
- msgescputs(from);
- }
- if (!strncasecmp(buf, "subj=", 5)) {
- strcpy(m_subject, &buf[5]);
- }
- if ((!strncasecmp(buf, "hnod=", 5))
- && (strcasecmp(&buf[5], serv_info.serv_humannode))) {
- wprintf("(%s) ", &buf[5]);
- }
- if ((!strncasecmp(buf, "room=", 5))
- && (strcasecmp(&buf[5], WC->wc_roomname))
- && (!IsEmptyStr(&buf[5])) ) {
- wprintf(_("in "));
- wprintf("%s> ", &buf[5]);
- }
- if (!strncasecmp(buf, "rfca=", 5)) {
- strcpy(rfca, &buf[5]);
- wprintf("<");
- msgescputs(rfca);
- wprintf("> ");
- }
- if (!strncasecmp(buf, "node=", 5)) {
- strcpy(node, &buf[5]);
- if ( ((WC->room_flags & QR_NETWORK)
- || ((strcasecmp(&buf[5], serv_info.serv_nodename)
- && (strcasecmp(&buf[5], serv_info.serv_fqdn)))))
- && (IsEmptyStr(rfca))
- ) {
- wprintf("@%s ", &buf[5]);
- }
- }
- if (!strncasecmp(buf, "rcpt=", 5)) {
- wprintf(_("to "));
- strcpy(to, &buf[5]);
- utf8ify_rfc822_string(to);
- wprintf("%s ", to);
- }
- if (!strncasecmp(buf, "time=", 5)) {
- webcit_fmt_date(now, atol(&buf[5]), 0);
- wprintf("%s ", now);
- }
- }
-
- /**
- * Save attachment info for later. We can't start downloading them
- * yet because we're in the middle of a server transaction.
- */
- if (!strncasecmp(buf, "part=", 5)) {
- ptr = malloc( (strlen(buf) + ((attachments != NULL) ? strlen(attachments) : 0)) ) ;
- if (ptr != NULL) {
- ++num_attachments;
- sprintf(ptr, "%s%s\n",
- ((attachments != NULL) ? attachments : ""),
- &buf[5]
- );
- free(attachments);
- attachments = ptr;
- lprintf(9, "attachments=<%s>\n", attachments);
- }
- }
-
- }
-
- if (include_headers) {
- wprintf("<br>");
-
- utf8ify_rfc822_string(m_subject);
- if (!IsEmptyStr(m_subject)) {
- wprintf(_("Subject:"));
- wprintf(" ");
- msgescputs(m_subject);
- wprintf("<br />");
- }
-
- /**
- * Begin body
- */
- wprintf("<br />");
- }
-
- /**
- * Learn the content type
- */
- strcpy(mime_content_type, "text/plain");
- while (serv_getln(buf, sizeof buf), (!IsEmptyStr(buf))) {
- if (!strcmp(buf, "000")) {
- wprintf("%s (4)", _("unexpected end of message"));
- goto ENDBODY;
- }
- if (!strncasecmp(buf, "Content-type: ", 14)) {
- int len;
- safestrncpy(mime_content_type, &buf[14],
- sizeof(mime_content_type));
- for (i=0; i<strlen(mime_content_type); ++i) {
- if (!strncasecmp(&mime_content_type[i], "charset=", 8)) {
- safestrncpy(mime_charset, &mime_content_type[i+8],
- sizeof mime_charset);
- }
- }
- len = strlen(mime_content_type);
- for (i=0; i<len; ++i) {
- if (mime_content_type[i] == ';') {
- mime_content_type[i] = 0;
- len = i - 1;
- }
- }
- len = strlen(mime_charset);
- for (i=0; i<len; ++i) {
- if (mime_charset[i] == ';') {
- mime_charset[i] = 0;
- len = i - 1;
- }
- }
- }
- }
-
- /** Set up a character set conversion if we need to (and if we can) */
-#ifdef HAVE_ICONV
- if ( (strcasecmp(mime_charset, "us-ascii"))
- && (strcasecmp(mime_charset, "UTF-8"))
- && (strcasecmp(mime_charset, ""))
- ) {
- ic = ctdl_iconv_open("UTF-8", mime_charset);
- if (ic == (iconv_t)(-1) ) {
- lprintf(5, "%s:%d iconv_open(%s, %s) failed: %s\n",
- __FILE__, __LINE__, "UTF-8", mime_charset, strerror(errno));
- }
- }
-#endif
-
- /** Messages in legacy Citadel variformat get handled thusly... */
- if (!strcasecmp(mime_content_type, "text/x-citadel-variformat")) {
- pullquote_fmout();
- }
-
- /* Boring old 80-column fixed format text gets handled this way... */
- else if (!strcasecmp(mime_content_type, "text/plain")) {
- while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
- int len;
- len = strlen(buf);
- if (buf[len-1] == '\n') buf[--len] = 0;
- if (buf[len-1] == '\r') buf[--len] = 0;
-
-#ifdef HAVE_ICONV
- if (ic != (iconv_t)(-1) ) {
- ibuf = buf;
- ibuflen = len;
- obuflen = SIZ;
- obuf = (char *) malloc(obuflen);
- osav = obuf;
- iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
- osav[SIZ-obuflen] = 0;
- safestrncpy(buf, osav, sizeof buf);
- free(osav);
- }
-#endif
-
- len = strlen(buf);
- while ((!IsEmptyStr(buf)) && (isspace(buf[len - 1])))
- buf[--len] = 0;
- if ((bq == 0) &&
- ((!strncmp(buf, ">", 1)) || (!strncmp(buf, " >", 2)) )) {
- wprintf("<blockquote>");
- bq = 1;
- } else if ((bq == 1) &&
- (strncmp(buf, ">", 1)) && (strncmp(buf, " >", 2)) ) {
- wprintf("</blockquote>");
- bq = 0;
- }
- wprintf("<tt>");
- url(buf);
- msgescputs1(buf);
- wprintf("</tt><br />");
- }
- wprintf("</i><br />");
- }
-
- /** HTML just gets escaped and stuffed back into the editor */
- else if (!strcasecmp(mime_content_type, "text/html")) {
- while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
- strcat(buf, "\n");
- msgescputs(buf);
- }
- }//// TODO: charset? utf8?
-
- /** Unknown weirdness ... don't know how to handle this content type */
- else {
- while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { }
- }
-
-ENDBODY:
- /** end of body handler */
-
- /*
- * If there were attachments, we have to download them and insert them
- * into the attachment chain for the forwarded message we are composing.
- */
- if ( (forward_attachments) && (num_attachments) ) {
- for (i=0; i<num_attachments; ++i) {
- extract_token(buf, attachments, i, '\n', sizeof buf);
- extract_token(mime_filename, buf, 1, '|', sizeof mime_filename);
- extract_token(mime_partnum, buf, 2, '|', sizeof mime_partnum);
- extract_token(mime_disposition, buf, 3, '|', sizeof mime_disposition);
- extract_token(mime_content_type, buf, 4, '|', sizeof mime_content_type);
- mime_length = extract_int(buf, 5);
-
- /*
- * tracing ... uncomment if necessary
- *
- */
- lprintf(9, "fwd filename: %s\n", mime_filename);
- lprintf(9, "fwd partnum : %s\n", mime_partnum);
- lprintf(9, "fwd conttype: %s\n", mime_content_type);
- lprintf(9, "fwd dispose : %s\n", mime_disposition);
- lprintf(9, "fwd length : %d\n", mime_length);
-
- if ( (!strcasecmp(mime_disposition, "inline"))
- || (!strcasecmp(mime_disposition, "attachment")) ) {
-
- /* Create an attachment struct from this mime part... */
- att = malloc(sizeof(struct wc_attachment));
- memset(att, 0, sizeof(struct wc_attachment));
- att->length = mime_length;
- strcpy(att->content_type, mime_content_type);
- strcpy(att->filename, mime_filename);
- att->next = NULL;
- att->data = load_mimepart(msgnum, mime_partnum);
-
- /* And add it to the list. */
- if (WC->first_attachment == NULL) {
- WC->first_attachment = att;
- }
- else {
- aptr = WC->first_attachment;
- while (aptr->next != NULL) aptr = aptr->next;
- aptr->next = att;
- }
- }
-
- }
- }
-
-#ifdef HAVE_ICONV
- if (ic != (iconv_t)(-1) ) {
- iconv_close(ic);
- }
-#endif
-
- if (attachments != NULL) {
- free(attachments);
- }
-}
-
-/**
- * \brief Display one row in the mailbox summary view
- *
- * \param num The row number to be displayed
- */
-void display_summarized(int num) {
- char datebuf[64];
-
- wprintf("<tr id=\"m%ld\" style=\"font-weight:%s;\" "
- "onMouseDown=\"CtdlMoveMsgMouseDown(event,%ld)\">",
- WC->summ[num].msgnum,
- (WC->summ[num].is_new ? "bold" : "normal"),
- WC->summ[num].msgnum
- );
-
- wprintf("<td width=%d%%>", SUBJ_COL_WIDTH_PCT);
-
- escputs(WC->summ[num].subj);//////////////////////////////////TODO: QP DECODE
- wprintf("</td>");
-
- wprintf("<td width=%d%%>", SENDER_COL_WIDTH_PCT);
- escputs(WC->summ[num].from);
- wprintf("</td>");
-
- wprintf("<td width=%d%%>", DATE_PLUS_BUTTONS_WIDTH_PCT);
- webcit_fmt_date(datebuf, WC->summ[num].date, 1); /* brief */
- escputs(datebuf);
- wprintf("</td>");
-
- wprintf("</tr>\n");
-}
-
-
-
-/**
- * \brief display the adressbook overview
- * \param msgnum the citadel message number
- * \param alpha what????
- */
-void display_addressbook(long msgnum, char alpha) {
- char buf[SIZ];
- char mime_partnum[SIZ];
- char mime_filename[SIZ];
- char mime_content_type[SIZ];
- char mime_disposition[SIZ];
- int mime_length;
- char vcard_partnum[SIZ];
- char *vcard_source = NULL;
- struct message_summary summ;
-
- memset(&summ, 0, sizeof(summ));
- safestrncpy(summ.subj, _("(no subject)"), sizeof summ.subj);
-
- sprintf(buf, "MSG0 %ld|1", msgnum); /* ask for headers only */
- serv_puts(buf);
- serv_getln(buf, sizeof buf);
- if (buf[0] != '1') return;
-
- while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
- if (!strncasecmp(buf, "part=", 5)) {
- extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
- extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
- extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
- extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
- mime_length = extract_int(&buf[5], 5);
-
- if ( (!strcasecmp(mime_content_type, "text/x-vcard"))
- || (!strcasecmp(mime_content_type, "text/vcard")) ) {
- strcpy(vcard_partnum, mime_partnum);
- }
-
- }
- }
-
- if (!IsEmptyStr(vcard_partnum)) {
- vcard_source = load_mimepart(msgnum, vcard_partnum);
- if (vcard_source != NULL) {
-
- /** Display the summary line */
- display_vcard(vcard_source, alpha, 0, NULL);
-
- /** If it's my vCard I can edit it */
- if ( (!strcasecmp(WC->wc_roomname, USERCONFIGROOM))
- || (!strcasecmp(&WC->wc_roomname[11], USERCONFIGROOM))
- || (WC->wc_view == VIEW_ADDRESSBOOK)
- ) {
- wprintf("<a href=\"edit_vcard?"
- "msgnum=%ld?partnum=%s\">",
- msgnum, vcard_partnum);
- wprintf("[%s]</a>", _("edit"));
- }
-
- free(vcard_source);
- }
- }
-
-}
-
-
-
-/**
- * \brief If it's an old "Firstname Lastname" style record, try to convert it.
- * \param namebuf name to analyze, reverse if nescessary
- */
-void lastfirst_firstlast(char *namebuf) {
- char firstname[SIZ];
- char lastname[SIZ];
- int i;
-
- if (namebuf == NULL) return;
- if (strchr(namebuf, ';') != NULL) return;
-
- i = num_tokens(namebuf, ' ');
- if (i < 2) return;
-
- extract_token(lastname, namebuf, i-1, ' ', sizeof lastname);
- remove_token(namebuf, i-1, ' ');
- strcpy(firstname, namebuf);
- sprintf(namebuf, "%s; %s", lastname, firstname);
-}
-
-/**
- * \brief fetch what??? name
- * \param msgnum the citadel message number
- * \param namebuf where to put the name in???
- */
-void fetch_ab_name(long msgnum, char *namebuf) {
- char buf[SIZ];
- char mime_partnum[SIZ];
- char mime_filename[SIZ];
- char mime_content_type[SIZ];
- char mime_disposition[SIZ];
- int mime_length;
- char vcard_partnum[SIZ];
- char *vcard_source = NULL;
- int i, len;
- struct message_summary summ;
-
- if (namebuf == NULL) return;
- strcpy(namebuf, "");
-
- memset(&summ, 0, sizeof(summ));
- safestrncpy(summ.subj, "(no subject)", sizeof summ.subj);
-
- sprintf(buf, "MSG0 %ld|0", msgnum); /** unfortunately we need the mime info now */
- serv_puts(buf);
- serv_getln(buf, sizeof buf);
- if (buf[0] != '1') return;
-
- while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
- if (!strncasecmp(buf, "part=", 5)) {
- extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
- extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
- extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
- extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
- mime_length = extract_int(&buf[5], 5);
-
- if ( (!strcasecmp(mime_content_type, "text/x-vcard"))
- || (!strcasecmp(mime_content_type, "text/vcard")) ) {
- strcpy(vcard_partnum, mime_partnum);
- }
-
- }
- }
-
- if (!IsEmptyStr(vcard_partnum)) {
- vcard_source = load_mimepart(msgnum, vcard_partnum);
- if (vcard_source != NULL) {
-
- /* Grab the name off the card */
- display_vcard(vcard_source, 0, 0, namebuf);
-
- free(vcard_source);
- }
- }
-
- lastfirst_firstlast(namebuf);
- striplt(namebuf);
- len = strlen(namebuf);
- for (i=0; i<len; ++i) {
- if (namebuf[i] != ';') return;
- }
- strcpy(namebuf, _("(no name)"));
-}
-
-
-
-/**
- * \brief Record compare function for sorting address book indices
- * \param ab1 adressbook one
- * \param ab2 adressbook two
- */
-int abcmp(const void *ab1, const void *ab2) {
- return(strcasecmp(
- (((const struct addrbookent *)ab1)->ab_name),
- (((const struct addrbookent *)ab2)->ab_name)
- ));
-}
-
-
-/**
- * \brief Helper function for do_addrbook_view()
- * Converts a name into a three-letter tab label
- * \param tabbuf the tabbuffer to add name to
- * \param name the name to add to the tabbuffer
- */
-void nametab(char *tabbuf, long len, char *name) {
- stresc(tabbuf, len, name, 0, 0);
- tabbuf[0] = toupper(tabbuf[0]);
- tabbuf[1] = tolower(tabbuf[1]);
- tabbuf[2] = tolower(tabbuf[2]);
- tabbuf[3] = 0;
-}
-
-
-/**
- * \brief Render the address book using info we gathered during the scan
- * \param addrbook the addressbook to render
- * \param num_ab the number of the addressbook
- */
-void do_addrbook_view(struct addrbookent *addrbook, int num_ab) {
- int i = 0;
- int displayed = 0;
- int bg = 0;
- static int NAMESPERPAGE = 60;
- int num_pages = 0;
- int tabfirst = 0;
- char tabfirst_label[64];
- int tablast = 0;
- char tablast_label[64];
- char this_tablabel[64];
- int page = 0;
- char **tablabels;
-
- if (num_ab == 0) {
- wprintf("<br /><br /><br /><div align=\"center\"><i>");
- wprintf(_("This address book is empty."));
- wprintf("</i></div>\n");
- return;
- }
-
- if (num_ab > 1) {
- qsort(addrbook, num_ab, sizeof(struct addrbookent), abcmp);
- }
-
- num_pages = (num_ab / NAMESPERPAGE) + 1;
-
- tablabels = malloc(num_pages * sizeof (char *));
- if (tablabels == NULL) {
- wprintf("<br /><br /><br /><div align=\"center\"><i>");
- wprintf(_("An internal error has occurred."));
- wprintf("</i></div>\n");
- return;
- }
-
- for (i=0; i<num_pages; ++i) {
- tabfirst = i * NAMESPERPAGE;
- tablast = tabfirst + NAMESPERPAGE - 1;
- if (tablast > (num_ab - 1)) tablast = (num_ab - 1);
- nametab(tabfirst_label, 64, addrbook[tabfirst].ab_name);
- nametab(tablast_label, 64, addrbook[tablast].ab_name);
- sprintf(this_tablabel, "%s - %s", tabfirst_label, tablast_label);
- tablabels[i] = strdup(this_tablabel);
- }
-
- tabbed_dialog(num_pages, tablabels);
- page = (-1);
-
- for (i=0; i<num_ab; ++i) {
-
- if ((i / NAMESPERPAGE) != page) { /* New tab */
- page = (i / NAMESPERPAGE);
- if (page > 0) {
- wprintf("</tr></table>\n");
- end_tab(page-1, num_pages);
- }
- begin_tab(page, num_pages);
- wprintf("<table border=0 cellspacing=0 cellpadding=3 width=100%%>\n");
- displayed = 0;
- }
-
- if ((displayed % 4) == 0) {
- if (displayed > 0) {
- wprintf("</tr>\n");
- }
- bg = 1 - bg;
- wprintf("<tr bgcolor=\"#%s\">",
- (bg ? "DDDDDD" : "FFFFFF")
- );
- }
-
- wprintf("<td>");
-
- wprintf("<a href=\"readfwd?startmsg=%ld&is_singlecard=1",
- addrbook[i].ab_msgnum);
- wprintf("?maxmsgs=1?is_summary=0?alpha=%s\">", bstr("alpha"));
- vcard_n_prettyize(addrbook[i].ab_name);
- escputs(addrbook[i].ab_name);
- wprintf("</a></td>\n");
- ++displayed;
- }
-
- wprintf("</tr></table>\n");
- end_tab((num_pages-1), num_pages);
-
- for (i=0; i<num_pages; ++i) {
- free(tablabels[i]);
- }
- free(tablabels);
-}
-
-
-
-/**
- * \brief load message pointers from the server
- * \param servcmd the citadel command to send to the citserver
- * \param with_headers what headers???
- */
-int load_msg_ptrs(char *servcmd, int with_headers)
-{
- char buf[1024];
- time_t datestamp;
- char fullname[128];
- char nodename[128];
- char inetaddr[128];
- char subject[1024];
- int nummsgs;
- int sbjlen;
- int maxload = 0;
-
- int num_summ_alloc = 0;
-
- if (WC->summ != NULL) {
- free(WC->summ);
- WC->num_summ = 0;
- WC->summ = NULL;
- }
- num_summ_alloc = 100;
- WC->num_summ = 0;
- WC->summ = malloc(num_summ_alloc * sizeof(struct message_summary));
-
- nummsgs = 0;
- maxload = sizeof(WC->msgarr) / sizeof(long) ;
- serv_puts(servcmd);
- serv_getln(buf, sizeof buf);
- if (buf[0] != '1') {
- return (nummsgs);
- }
- while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
- if (nummsgs < maxload) {
- WC->msgarr[nummsgs] = extract_long(buf, 0);
- datestamp = extract_long(buf, 1);
- extract_token(fullname, buf, 2, '|', sizeof fullname);
- extract_token(nodename, buf, 3, '|', sizeof nodename);
- extract_token(inetaddr, buf, 4, '|', sizeof inetaddr);
- extract_token(subject, buf, 5, '|', sizeof subject);
- ++nummsgs;
-
- if (with_headers) {
- if (nummsgs > num_summ_alloc) {
- num_summ_alloc *= 2;
- WC->summ = realloc(WC->summ,
- num_summ_alloc * sizeof(struct message_summary));
- }
- ++WC->num_summ;
-
- memset(&WC->summ[nummsgs-1], 0, sizeof(struct message_summary));
- WC->summ[nummsgs-1].msgnum = WC->msgarr[nummsgs-1];
- safestrncpy(WC->summ[nummsgs-1].subj,
- _("(no subject)"), sizeof WC->summ[nummsgs-1].subj);
- if (!IsEmptyStr(fullname)) {
- /** Handle senders with RFC2047 encoding */
- utf8ify_rfc822_string(fullname);
- safestrncpy(WC->summ[nummsgs-1].from,
- fullname, sizeof WC->summ[nummsgs-1].from);
- }
- if (!IsEmptyStr(subject)) {
- /** Handle subjects with RFC2047 encoding */
- utf8ify_rfc822_string(subject);
- safestrncpy(WC->summ[nummsgs-1].subj, subject,
- sizeof WC->summ[nummsgs-1].subj);
- }
- sbjlen = Ctdl_Utf8StrLen(WC->summ[nummsgs-1].subj);
- if (sbjlen > 75) {
- char *ptr;
- ptr = Ctdl_Utf8StrCut(WC->summ[nummsgs-1].subj, 72);
-
- strcpy(ptr, "...");
- }
-
- if (!IsEmptyStr(nodename)) {
- if ( ((WC->room_flags & QR_NETWORK)
- || ((strcasecmp(nodename, serv_info.serv_nodename)
- && (strcasecmp(nodename, serv_info.serv_fqdn)))))
- ) {
- strcat(WC->summ[nummsgs-1].from, " @ ");
- strcat(WC->summ[nummsgs-1].from, nodename);
- }
- }
-
- WC->summ[nummsgs-1].date = datestamp;
-
- /** Handle senders with RFC2047 encoding */
- utf8ify_rfc822_string(WC->summ[nummsgs-1].from);
- if (strlen(WC->summ[nummsgs-1].from) > 25) {
- strcpy(&WC->summ[nummsgs-1].from[22], "...");
- }
- }
- }
- }
- return (nummsgs);
-}
-
-/**
- * \brief qsort() compatible function to compare two longs in descending order.
- *
- * \param s1 first number to compare
- * \param s2 second number to compare
- */
-int longcmp_r(const void *s1, const void *s2) {
- long l1;
- long l2;
-
- l1 = *(long *)s1;
- l2 = *(long *)s2;
-
- if (l1 > l2) return(-1);
- if (l1 < l2) return(+1);
- return(0);
-}
-
-
-/**
- * \brief qsort() compatible function to compare two message summary structs by ascending subject.
- *
- * \param s1 first item to compare
- * \param s2 second item to compare
- */
-int summcmp_subj(const void *s1, const void *s2) {
- struct message_summary *summ1;
- struct message_summary *summ2;
-
- summ1 = (struct message_summary *)s1;
- summ2 = (struct message_summary *)s2;
- return strcasecmp(summ1->subj, summ2->subj);
-}
-
-/**
- * \brief qsort() compatible function to compare two message summary structs by descending subject.
- *
- * \param s1 first item to compare
- * \param s2 second item to compare
- */
-int summcmp_rsubj(const void *s1, const void *s2) {
- struct message_summary *summ1;
- struct message_summary *summ2;
-
- summ1 = (struct message_summary *)s1;
- summ2 = (struct message_summary *)s2;
- return strcasecmp(summ2->subj, summ1->subj);
-}
-
-/**
- * \brief qsort() compatible function to compare two message summary structs by ascending sender.
- *
- * \param s1 first item to compare
- * \param s2 second item to compare
- */
-int summcmp_sender(const void *s1, const void *s2) {
- struct message_summary *summ1;
- struct message_summary *summ2;
-
- summ1 = (struct message_summary *)s1;
- summ2 = (struct message_summary *)s2;
- return strcasecmp(summ1->from, summ2->from);
-}
-
-/**
- * \brief qsort() compatible function to compare two message summary structs by descending sender.
- *
- * \param s1 first item to compare
- * \param s2 second item to compare
- */
-int summcmp_rsender(const void *s1, const void *s2) {
- struct message_summary *summ1;
- struct message_summary *summ2;
-
- summ1 = (struct message_summary *)s1;
- summ2 = (struct message_summary *)s2;
- return strcasecmp(summ2->from, summ1->from);
-}
-
-/**
- * \brief qsort() compatible function to compare two message summary structs by ascending date.
- *
- * \param s1 first item to compare
- * \param s2 second item to compare
- */
-int summcmp_date(const void *s1, const void *s2) {
- struct message_summary *summ1;
- struct message_summary *summ2;
-
- summ1 = (struct message_summary *)s1;
- summ2 = (struct message_summary *)s2;
-
- if (summ1->date < summ2->date) return -1;
- else if (summ1->date > summ2->date) return +1;
- else return 0;
-}
-
-/**
- * \brief qsort() compatible function to compare two message summary structs by descending date.
- *
- * \param s1 first item to compare
- * \param s2 second item to compare
- */
-int summcmp_rdate(const void *s1, const void *s2) {
- struct message_summary *summ1;
- struct message_summary *summ2;
-
- summ1 = (struct message_summary *)s1;
- summ2 = (struct message_summary *)s2;
-
- if (summ1->date < summ2->date) return +1;
- else if (summ1->date > summ2->date) return -1;
- else return 0;
-}
-
-
-
-/**
- * \brief command loop for reading messages
- *
- * \param oper Set to "readnew" or "readold" or "readfwd" or "headers"
- */
-void readloop(char *oper)
-{
- char cmd[256] = "";
- char buf[SIZ];
- char old_msgs[SIZ];
- int a, b;