static HTMLState html_read_line(HTMLParser *parser) { gchar buf[HTMLBUFSIZE]; gchar *conv_str; gint index; if (fgets(buf, sizeof(buf), parser->fp) == NULL) { parser->state = HTML_EOF; return HTML_EOF; } conv_str = conv_convert(parser->conv, buf); if (!conv_str) { index = parser->bufp - parser->buf->str; conv_str = conv_utf8todisp(buf, NULL); g_string_append(parser->buf, conv_str); g_free(conv_str); parser->bufp = parser->buf->str + index; return HTML_CONV_FAILED; } index = parser->bufp - parser->buf->str; g_string_append(parser->buf, conv_str); g_free(conv_str); parser->bufp = parser->buf->str + index; return HTML_NORMAL; }
static SC_HTMLState sc_html_read_line(SC_HTMLParser *parser) { gchar buf[SC_HTMLBUFSIZE]; gchar buf2[SC_HTMLBUFSIZE]; gint index; if (parser->fp == NULL) return SC_HTML_EOF; if (fgets(buf, sizeof(buf), parser->fp) == NULL) { parser->state = SC_HTML_EOF; return SC_HTML_EOF; } if (conv_convert(parser->conv, buf2, sizeof(buf2), buf) < 0) { index = parser->bufp - parser->buf->str; conv_utf8todisp(buf2, sizeof(buf2), buf); g_string_append(parser->buf, buf2); parser->bufp = parser->buf->str + index; return SC_HTML_CONV_FAILED; } index = parser->bufp - parser->buf->str; g_string_append(parser->buf, buf2); parser->bufp = parser->buf->str + index; return SC_HTML_NORMAL; }
static void source_window_append(SourceWindow *sourcewin, const gchar *str) { GtkTextView *text = GTK_TEXT_VIEW(sourcewin->text); GtkTextBuffer *buffer = gtk_text_view_get_buffer(text); GtkTextIter iter; gchar *out; gint len; len = strlen(str) + 1; Xalloca(out, len, return); conv_utf8todisp(out, len, str); gtk_text_buffer_get_iter_at_offset(buffer, &iter, -1); gtk_text_buffer_insert(buffer, &iter, out, -1); }
static SC_HTMLState sc_html_read_line(SC_HTMLParser *parser) { gchar buf[SC_HTMLBUFSIZE]; gchar buf2[SC_HTMLBUFSIZE*4]; gint index; gint n; if (parser->fp == NULL) return SC_HTML_EOF; n = claws_fread(buf, 1, sizeof(buf) - 1, parser->fp); if (n == 0) { parser->state = SC_HTML_EOF; return SC_HTML_EOF; } else buf[n] = '\0'; if (conv_convert(parser->conv, buf2, sizeof(buf2), buf) < 0) { index = parser->bufp - parser->buf->str; conv_utf8todisp(buf2, sizeof(buf2), buf); g_string_append(parser->buf, buf2); parser->bufp = parser->buf->str + index; return SC_HTML_CONV_FAILED; } index = parser->bufp - parser->buf->str; g_string_append(parser->buf, buf2); parser->bufp = parser->buf->str + index; return SC_HTML_NORMAL; }
gchar *unmime_header(const gchar *encoded_str, gboolean addr_field) { const gchar *p = encoded_str; const gchar *eword_begin_p, *encoding_begin_p, *text_begin_p, *eword_end_p; gchar charset[32]; gchar encoding; gchar *conv_str; GString *outbuf; gchar *out_str; gsize out_len; int in_quote = FALSE; outbuf = g_string_sized_new(strlen(encoded_str) * 2); while (*p != '\0') { gchar *decoded_text = NULL; const gchar *quote_p; gint len; eword_begin_p = strstr(p, ENCODED_WORD_BEGIN); if (!eword_begin_p) { g_string_append(outbuf, p); break; } quote_p = p; while ((quote_p = strchr(quote_p, '"')) != NULL) { if (quote_p && quote_p < eword_begin_p) { /* Found a quote before the encoded word. */ in_quote = !in_quote; quote_p++; } if (quote_p >= eword_begin_p) break; } encoding_begin_p = strchr(eword_begin_p + 2, '?'); if (!encoding_begin_p) { g_string_append(outbuf, p); break; } text_begin_p = strchr(encoding_begin_p + 1, '?'); if (!text_begin_p) { g_string_append(outbuf, p); break; } eword_end_p = strstr(text_begin_p + 1, ENCODED_WORD_END); if (!eword_end_p) { g_string_append(outbuf, p); break; } if (p == encoded_str) { g_string_append_len(outbuf, p, eword_begin_p - p); p = eword_begin_p; } else { /* ignore spaces between encoded words */ const gchar *sp; for (sp = p; sp < eword_begin_p; sp++) { if (!g_ascii_isspace(*sp)) { g_string_append_len (outbuf, p, eword_begin_p - p); p = eword_begin_p; break; } } } len = MIN(sizeof(charset) - 1, encoding_begin_p - (eword_begin_p + 2)); memcpy(charset, eword_begin_p + 2, len); charset[len] = '\0'; encoding = g_ascii_toupper(*(encoding_begin_p + 1)); if (encoding == 'B') { gchar *tmp; tmp = g_strndup(text_begin_p + 1, eword_end_p - (text_begin_p + 1) + 1); decoded_text = g_base64_decode(tmp, &out_len); g_free(tmp); } else if (encoding == 'Q') { decoded_text = g_malloc (eword_end_p - (text_begin_p + 1) + 1); len = qp_decode_q_encoding (decoded_text, text_begin_p + 1, eword_end_p - (text_begin_p + 1)); } else { g_string_append_len(outbuf, p, eword_end_p + 2 - p); p = eword_end_p + 2; continue; } /* An encoded word MUST not appear within a quoted string, * so quoting that word after decoding should be safe. * We check there are no quotes just to be sure. If there * are, well, the comma won't pose a problem, probably. */ if (addr_field && strchr(decoded_text, ',') && !in_quote && !strchr(decoded_text, '"')) { gchar *tmp = g_strdup_printf("\"%s\"", decoded_text); g_free(decoded_text); decoded_text = tmp; } /* convert to UTF-8 */ conv_str = conv_codeset_strdup(decoded_text, charset, NULL); if (!conv_str || !g_utf8_validate(conv_str, -1, NULL)) { g_free(conv_str); conv_str = g_malloc(len + 1); conv_utf8todisp(conv_str, len + 1, decoded_text); } g_string_append(outbuf, conv_str); g_free(conv_str); g_free(decoded_text); p = eword_end_p + 2; } out_str = outbuf->str; out_len = outbuf->len; g_string_free(outbuf, FALSE); return g_realloc(out_str, out_len + 1); }