/*
* $Id$
- */
-/**
- * \defgroup MsgDisp Functions which deal with the fetching and displaying of messages.
- * \ingroup WebcitDisplayItems
+ *
+ * Functions which deal with the fetching and displaying of messages.
*
*/
-/*@{*/
+
#include "webcit.h"
#include "webserver.h"
#include "groupdav.h"
* \param buf the stringbuffer to process
*/
void utf8ify_rfc822_string(char *buf) {
- char *start, *end;
+ char *start, *end, *next, *nextend, *ptr;
char newbuf[1024];
char charset[128];
char encoding[16];
char *isav; /**< Saved pointer to input buffer */
char *osav; /**< Saved pointer to output buffer */
int passes = 0;
- int i, len;
+ int i, len, delta;
int illegal_non_rfc2047_encoding = 0;
/** Sometimes, badly formed messages contain strings which were simply
}
}
+ /* pre evaluate the first pair */
+ nextend = end = NULL;
+ len = strlen(buf);
+ start = strstr(buf, "=?");
+ if (start != NULL)
+ end = strstr(start, "?=");
+
+ while ((start != NULL) && (end != NULL))
+ {
+ next = strstr(end, "=?");
+ if (next != NULL)
+ nextend = strstr(next, "?=");
+ if (nextend == NULL)
+ next = NULL;
+
+ /* did we find two partitions */
+ if ((next != NULL) &&
+ ((next - end) > 2))
+ {
+ ptr = end + 2;
+ while ((ptr < next) &&
+ (isspace(*ptr) ||
+ (*ptr == '\r') ||
+ (*ptr == '\n') ||
+ (*ptr == '\t')))
+ ptr ++;
+ /* did we find a gab just filled with blanks? */
+ if (ptr == next)
+ {
+ memmove (end + 2,
+ next,
+ len - (next - start));
+
+ /* now terminate the gab at the end */
+ delta = (next - end) - 2;
+ len -= delta;
+ buf[len] = '\0';
+
+ /* move next to its new location. */
+ next -= delta;
+ nextend -= delta;
+ }
+ }
+ /* our next-pair is our new first pair now. */
+ start = next;
+ end = nextend;
+ }
+
/** Now we handle foreign character sets properly encoded
* in RFC2047 format.
*/
}
}
+#else
+inline void utf8ify_rfc822_string(char *a){};
+
#endif
}
len = strlen(v->prop[i].value);
-
+ /* if we have some untagged QP, detect it here. */
+ if (!is_qp && (strstr(v->prop[i].value, "=?")!=NULL))
+ utf8ify_rfc822_string(v->prop[i].value);
+
if (is_qp) {
// %ff can become 6 bytes in utf8
thisvalue = malloc(len * 2 + 3);
"<a href=\"display_enter"
"?force_room=_MAIL_?recp=");
+ len = strlen(mailto);
+ urlesc(&mailto[len], SIZ - len, "\"");
len = strlen(mailto);
urlesc(&mailto[len], SIZ - len, fullname);
len = strlen(mailto);
- urlesc(&mailto[len], SIZ - len, " <");
+ urlesc(&mailto[len], SIZ - len, "\" <");
len = strlen(mailto);
urlesc(&mailto[len], SIZ - len, thisvalue);
len = strlen(mailto);
name = vcard_get_prop(v, "n", 1, 0, 0);
if (name != NULL) {
+ utf8ify_rfc822_string(name);
strcpy(buf, name);
this_alpha = buf[0];
}
*/
void read_message(long msgnum, int printable_view, char *section) {
char buf[SIZ];
- char mime_partnum[256];
- char mime_name[256];
- char mime_filename[256];
- char escaped_mime_filename[256];
- char mime_content_type[256];
- char mime_charset[256];
- char mime_disposition[256];
+ 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[256];
- char m_cc[1024];
- char from[256];
- char node[256];
- char rfca[256];
- char reply_to[512];
- char reply_all[4096];
- char now[64];
+ 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 now[64] = "";
int format_type = 0;
int nhdr = 0;
int bq = 0;
int i = 0;
- char vcard_partnum[256];
- char cal_partnum[256];
+ char vcard_partnum[256] = "";
+ char cal_partnum[256] = "";
char *part_source = NULL;
- char msg4_partnum[32];
+ char msg4_partnum[32] = "";
#ifdef HAVE_ICONV
iconv_t ic = (iconv_t)(-1) ;
char *ibuf; /**< Buffer of characters to be converted */
char *osav; /**< Saved pointer to output buffer */
#endif
- strcpy(from, "");
- strcpy(node, "");
- strcpy(rfca, "");
- strcpy(reply_to, "");
- strcpy(reply_all, "");
- strcpy(vcard_partnum, "");
- strcpy(cal_partnum, "");
strcpy(mime_content_type, "text/plain");
strcpy(mime_charset, "us-ascii");
strcpy(mime_submessages, "");
strcpy(from, &buf[5]);
wprintf(_("from "));
wprintf("<a href=\"showuser?who=");
-#ifdef HAVE_ICONV
utf8ify_rfc822_string(from);
-#endif
urlescputs(from);
wprintf("\">");
escputs(from);
len = strlen(reply_all);
safestrncpy(&reply_all[len], &buf[5],
(sizeof reply_all - len) );
-#ifdef HAVE_ICONV
utf8ify_rfc822_string(&buf[5]);
-#endif
escputs(&buf[5]);
wprintf(" ");
}
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=\"static/diskette_24x.gif\" "
+ "<img src=\"display_mime_icon?type=%s\" "
"border=0 align=middle>\n"
"%s (%s, %d bytes) [ "
"<a href=\"mimepart/%ld/%s/%s\""
" | "
"<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,
wprintf("****");
}
-#ifdef HAVE_ICONV
utf8ify_rfc822_string(m_cc);
utf8ify_rfc822_string(m_subject);
-#endif
/** start msg buttons */
*/
strcpy(mime_content_type, "text/plain");
while (serv_getln(buf, sizeof buf), (!IsEmptyStr(buf))) {
- lprintf(9, "GOT: <%s>\n", buf);
if (!strcmp(buf, "000")) {
/* This is not necessarily an error condition. See bug #226. */
goto ENDBODY;
char from[256];
char node[256];
char rfca[256];
+ char to[256];
char reply_to[512];
char now[256];
int format_type = 0;
if (!strncasecmp(buf, "from=", 5)) {
strcpy(from, &buf[5]);
wprintf(_("from "));
-#ifdef HAVE_ICONV
utf8ify_rfc822_string(from);
-#endif
msgescputs(from);
}
if (!strncasecmp(buf, "subj=", 5)) {
}
if (!strncasecmp(buf, "rcpt=", 5)) {
wprintf(_("to "));
- wprintf("%s ", &buf[5]);
+ strcpy(to, &buf[5]);
+ utf8ify_rfc822_string(to);
+ wprintf("%s ", to);
}
if (!strncasecmp(buf, "time=", 5)) {
webcit_fmt_date(now, atol(&buf[5]), 0);
if (include_headers) {
wprintf("<br>");
-#ifdef HAVE_ICONV
utf8ify_rfc822_string(m_subject);
-#endif
if (!IsEmptyStr(m_subject)) {
wprintf(_("Subject:"));
wprintf(" ");
safestrncpy(WC->summ[nummsgs-1].subj,
_("(no subject)"), sizeof WC->summ[nummsgs-1].subj);
if (!IsEmptyStr(fullname)) {
-#ifdef HAVE_ICONV
/** Handle senders with RFC2047 encoding */
utf8ify_rfc822_string(fullname);
-#endif
safestrncpy(WC->summ[nummsgs-1].from,
fullname, sizeof WC->summ[nummsgs-1].from);
}
if (!IsEmptyStr(subject)) {
-#ifdef HAVE_ICONV
/** Handle subjects with RFC2047 encoding */
utf8ify_rfc822_string(subject);
-#endif
safestrncpy(WC->summ[nummsgs-1].subj, subject,
sizeof WC->summ[nummsgs-1].subj);
}
WC->summ[nummsgs-1].date = datestamp;
-#ifdef HAVE_ICONV
/** Handle senders with RFC2047 encoding */
utf8ify_rfc822_string(WC->summ[nummsgs-1].from);
-#endif
if (strlen(WC->summ[nummsgs-1].from) > 25) {
strcpy(&WC->summ[nummsgs-1].from[22], "...");
}
* new messages.
*/
strcpy(old_msgs, "");
- if (is_summary) {
+ if ((is_summary) || (WCC->wc_default_view == VIEW_CALENDAR)){
serv_puts("GTSN");
serv_getln(buf, sizeof buf);
if (buf[0] == '2') {
if (WCC->wc_default_view == VIEW_CALENDAR) { /**< calendar */
is_calendar = 1;
- strcpy(cmd, "MSGS ALL");
+ strcpy(cmd, "MSGS ALL|||1");
maxmsgs = 32767;
}
if (WCC->wc_default_view == VIEW_TASKS) { /**< tasks */
goto DONE;
}
- if (is_summary) {
+ if ((is_summary) || (WCC->wc_default_view == VIEW_CALENDAR)){
for (a = 0; a < nummsgs; ++a) {
/** Are you a new message, or an old message? */
if (is_summary) {
addrbook[num_ab-1].ab_msgnum = WCC->msgarr[a];
}
else if (is_calendar) {
- display_calendar(WCC->msgarr[a]);
+ display_calendar(WCC->msgarr[a], WCC->summ[a].is_new);
}
else if (is_tasks) {
- display_task(WCC->msgarr[a]);
+ display_task(WCC->msgarr[a], WCC->summ[a].is_new);
}
else if (is_notes) {
- display_note(WCC->msgarr[a]);
+ display_note(WCC->msgarr[a], WCC->summ[a].is_new);
}
else {
if (displayed_msgs == NULL) {
* ... this is where the actual message gets transmitted to the server.
*/
void post_mime_to_server(void) {
- char boundary[SIZ];
+ char top_boundary[SIZ];
+ char alt_boundary[SIZ];
int is_multipart = 0;
static int seq = 0;
struct wc_attachment *att;
char *encoded;
size_t encoded_length;
size_t encoded_strlen;
+ char *txtmail = NULL;
+
+ sprintf(top_boundary, "Citadel--Multipart--%s--%04x--%04x",
+ serv_info.serv_fqdn,
+ getpid(),
+ ++seq
+ );
+ sprintf(alt_boundary, "Citadel--Multipart--%s--%04x--%04x",
+ serv_info.serv_fqdn,
+ getpid(),
+ ++seq
+ );
/** RFC2045 requires this, and some clients look for it... */
serv_puts("MIME-Version: 1.0");
}
if (is_multipart) {
- sprintf(boundary, "Citadel--Multipart--%s--%04x--%04x",
- serv_info.serv_fqdn,
- getpid(),
- ++seq
- );
-
/** Remember, serv_printf() appends an extra newline */
serv_printf("Content-type: multipart/mixed; "
- "boundary=\"%s\"\n", boundary);
+ "boundary=\"%s\"\n", top_boundary);
serv_printf("This is a multipart message in MIME format.\n");
- serv_printf("--%s", boundary);
+ serv_printf("--%s", top_boundary);
}
+
+
+ /* Remember, serv_printf() appends an extra newline */
+ serv_printf("Content-type: multipart/alternative; "
+ "boundary=\"%s\"\n", alt_boundary);
+ serv_printf("This is a multipart message in MIME format.\n");
+ serv_printf("--%s", alt_boundary);
+
+ serv_puts("Content-type: text/plain; charset=utf-8");
+ serv_puts("Content-Transfer-Encoding: quoted-printable");
+ serv_puts("");
+ txtmail = html_to_ascii(bstr("msgtext"), 0, 80, 0);
+ text_to_server_qp(txtmail); /** Transmit message in quoted-printable encoding */
+ free(txtmail);
+
+ serv_printf("--%s", alt_boundary);
+
serv_puts("Content-type: text/html; charset=utf-8");
serv_puts("Content-Transfer-Encoding: quoted-printable");
serv_puts("");
serv_puts("<html><body>\r\n");
text_to_server_qp(bstr("msgtext")); /** Transmit message in quoted-printable encoding */
serv_puts("</body></html>\r\n");
+
+
+ serv_printf("--%s--", alt_boundary);
+
+
+
+
if (is_multipart) {
if (encoded == NULL) break;
encoded_strlen = CtdlEncodeBase64(encoded, att->data, att->length, 1);
- serv_printf("--%s", boundary);
+ serv_printf("--%s", top_boundary);
serv_printf("Content-type: %s", att->content_type);
serv_printf("Content-disposition: attachment; "
"filename=\"%s\"", att->filename);
serv_puts("");
free(encoded);
}
- serv_printf("--%s--", boundary);
+ serv_printf("--%s--", top_boundary);
}
serv_puts("000");
return;
}
-#ifdef WEBCIT_WITH_CALENDAR_SERVICE
- /**
+ /*
* Are we perhaps in a calendar room? If so, then an "enter
* message" command really means "add new calendar item."
*/
return;
}
- /**
+ /*
* Are we perhaps in a tasks view? If so, then an "enter
* message" command really means "add new task."
*/
display_edit_task();
return;
}
-#endif
- /**
+ /*
* Otherwise proceed normally.
* Do a custom room banner with no navbar...
*/
wprintf("</td></tr>");
if (recipient_required) {
-
+ char *ccraw;
+ char *copy;
+ size_t len;
wprintf("<tr><th><label for=\"recp_id\"> ");
wprintf(_("To:"));
wprintf("</label></th>"
"<td><input autocomplete=\"off\" type=\"text\" name=\"recp\" id=\"recp_id\" value=\"");
- escputs(bstr("recp"));
+ ccraw = bstr("recp");
+ len = strlen(ccraw);
+ copy = (char*) malloc(len * 2 + 1);
+ memcpy(copy, ccraw, len + 1);
+ utf8ify_rfc822_string(copy);
+ escputs(copy);
+ free(copy);
wprintf("\" size=45 maxlength=1000 />");
wprintf("<div class=\"auto_complete\" id=\"recp_name_choices\"></div>");
wprintf("</td><td rowspan=\"3\" align=\"left\" valign=\"top\">");
wprintf(_("CC:"));
wprintf("</label></th>"
"<td><input autocomplete=\"off\" type=\"text\" name=\"cc\" id=\"cc_id\" value=\"");
- escputs(bstr("cc"));
+ ccraw = bstr("cc");
+ len = strlen(ccraw);
+ copy = (char*) malloc(len * 2 + 1);
+ memcpy(copy, ccraw, len + 1);
+ utf8ify_rfc822_string(copy);
+ escputs(copy);
+ free(copy);
wprintf("\" size=45 maxlength=1000 />");
wprintf("<div class=\"auto_complete\" id=\"cc_name_choices\"></div>");
wprintf("</td></tr>");
wprintf(_("BCC:"));
wprintf("</label></th>"
"<td><input autocomplete=\"off\" type=\"text\" name=\"bcc\" id=\"bcc_id\" value=\"");
- escputs(bstr("bcc"));
+ ccraw = bstr("bcc");
+ len = strlen(ccraw);
+ copy = (char*) malloc(len * 2 + 1);
+ memcpy(copy, ccraw, len + 1);
+ utf8ify_rfc822_string(copy);
+ escputs(copy);
+ free(copy);
wprintf("\" size=45 maxlength=1000 />");
wprintf("<div class=\"auto_complete\" id=\"bcc_name_choices\"></div>");
wprintf("</td></tr>");