/*
* Output an HTML message, modifying it slightly to make sure it plays nice
* with the rest of our web framework.
*
* Copyright (c) 2005-2012 by the citadel.org team
*
* This program is open source software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License, version 3.
*
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
*
*/
#include "webcit.h"
#include "webserver.h"
/*
* Strip surrounding single or double quotes from a string.
*/
void stripquotes(char *s)
{
int len;
if (!s) return;
len = strlen(s);
if (len < 2) return;
if ( ( (s[0] == '\"') && (s[len-1] == '\"') ) || ( (s[0] == '\'') && (s[len-1] == '\'') ) ) {
s[len-1] = 0;
strcpy(s, &s[1]);
}
}
/*
* Check to see if a META tag has overridden the declared MIME character set.
*
* charset Character set name (left unchanged if we don't do anything)
* meta_http_equiv Content of the "http-equiv" portion of the META tag
* meta_content Content of the "content" portion of the META tag
*/
void extract_charset_from_meta(char *charset, char *meta_http_equiv, char *meta_content)
{
char *ptr;
char buf[64];
if (!charset) return;
if (!meta_http_equiv) return;
if (!meta_content) return;
if (strcasecmp(meta_http_equiv, "Content-type")) return;
ptr = strchr(meta_content, ';');
if (!ptr) return;
safestrncpy(buf, ++ptr, sizeof buf);
striplt(buf);
if (!strncasecmp(buf, "charset=", 8)) {
strcpy(charset, &buf[8]);
/*
* The brain-damaged webmail program in Microsoft Exchange declares
* a charset of "unicode" when they really mean "UTF-8". GNU iconv
* treats "unicode" as an alias for "UTF-16" so we have to manually
* fix this here, otherwise messages generated in Exchange webmail
* show up as a big pile of weird characters.
*/
if (!strcasecmp(charset, "unicode")) {
strcpy(charset, "UTF-8");
}
/* Remove wandering punctuation */
if ((ptr=strchr(charset, '\"'))) *ptr = 0;
striplt(charset);
}
}
/*
* Sanitize and enhance an HTML message for display.
* Also convert weird character sets to UTF-8 if necessary.
* Also fixup img src="cid:..." type inline images to fetch the image
*
*/
void output_html(const char *supplied_charset, int treat_as_wiki, int msgnum, StrBuf *Source, StrBuf *Target) {
char buf[SIZ];
char *msg;
char *ptr;
char *msgstart;
char *msgend;
StrBuf *converted_msg;
int buffer_length = 1;
int line_length = 0;
int content_length = 0;
char new_window[SIZ];
int brak = 0;
int alevel = 0;
int scriptlevel = 0;
int script_start_pos = (-1);
int i;
int linklen;
char charset[128];
StrBuf *BodyArea = NULL;
#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
if (Target == NULL)
Target = WC->WBuf;
safestrncpy(charset, supplied_charset, sizeof charset);
msg = strdup("");
sprintf(new_window, "");
StrBufAppendPrintf(Target, _("realloc() error! couldn't get %d bytes: %s"),
buffer_length + 1,
strerror(errno));
StrBufAppendPrintf(Target, "