return str;
}
+/* remove CR (carriage return) */
+gchar *strcrchomp(gchar *str)
+{
+ register gchar *s;
+
+ if (!*str) return str;
+
+ s = str + strlen(str) - 1;
+ if (*s == '\n' && s > str && *(s - 1) == '\r') {
+ *(s - 1) = '\n';
+ *s = '\0';
+ }
+
+ return str;
+}
/* Similar to `strstr' but this function ignores the case of both strings. */
gchar *strcasestr(const gchar *haystack, const gchar *needle)
if (!s1 || !s2) return -1;
if (!*s1 || !*s2) return -1;
- Xalloca(str1, strlen(s1) + 1, return -1);
- Xalloca(str2, strlen(s2) + 1, return -1);
- strcpy(str1, s1);
- strcpy(str2, s2);
+ Xstrdup_a(str1, s1, return -1);
+ Xstrdup_a(str2, s2, return -1);
trim_subject(str1);
trim_subject(str2);
register gchar *p;
if ((str = strchr(str, quote_chr))) {
- if ((p = strchr(str + 1, quote_chr))) {
+ p = str;
+ while ((p = strchr(p + 1, quote_chr)) && (p[-1] == '\\')) {
+ memmove(p - 1, p, strlen(p) + 1);
+ p--;
+ }
+ if(p) {
*p = '\0';
memmove(str, str + 1, p - str);
}
return group_list;
}
+GList *add_history(GList *list, const gchar *str)
+{
+ GList *old;
+
+ g_return_val_if_fail(str != NULL, list);
+
+ old = g_list_find_custom(list, (gpointer)str, (GCompareFunc)strcmp2);
+ if (old) {
+ g_free(old->data);
+ list = g_list_remove(list, old->data);
+ } else if (g_list_length(list) >= MAX_HISTORY_SIZE) {
+ GList *last;
+
+ last = g_list_last(list);
+ if (last) {
+ g_free(last->data);
+ g_list_remove(list, last->data);
+ }
+ }
+
+ list = g_list_prepend(list, g_strdup(str));
+
+ return list;
+}
+
void remove_return(gchar *str)
{
register gchar *p = str;
return mime_tmp_dir;
}
+gchar *get_template_dir(void)
+{
+ static gchar *template_dir = NULL;
+
+ if (!template_dir)
+ template_dir = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
+ TEMPLATE_DIR, NULL);
+
+ return template_dir;
+}
+
gchar *get_tmp_file(void)
{
static gchar *tmp_file = NULL;
return ret;
}
+static gint is_unchanged_uri_char(char c)
+{
+ switch (c) {
+ case '(':
+ case ')':
+ case ',':
+ return 0;
+ default:
+ return 1;
+ }
+}
+
+void encode_uri(gchar *encoded_uri, gint bufsize, const gchar *uri)
+{
+ int i;
+ int k;
+
+ k = 0;
+ for(i = 0; i < strlen(uri) ; i++) {
+ if (is_unchanged_uri_char(uri[i])) {
+ if (k + 2 >= bufsize)
+ break;
+ encoded_uri[k++] = uri[i];
+ }
+ else {
+ char * hexa = "0123456789ABCDEF";
+
+ if (k + 4 >= bufsize)
+ break;
+ encoded_uri[k++] = '%';
+ encoded_uri[k++] = hexa[uri[i] / 16];
+ encoded_uri[k++] = hexa[uri[i] % 16];
+ }
+ }
+ encoded_uri[k] = 0;
+}
+
+/* Converts two-digit hexadecimal to decimal. Used for unescaping escaped
+ * characters
+ */
+static gint axtoi(const gchar *hexstr)
+{
+ gint hi, lo, result;
+
+ hi = hexstr[0];
+ if ('0' <= hi && hi <= '9') {
+ hi -= '0';
+ } else
+ if ('a' <= hi && hi <= 'f') {
+ hi -= ('a' - 10);
+ } else
+ if ('A' <= hi && hi <= 'F') {
+ hi -= ('A' - 10);
+ }
+
+ lo = hexstr[1];
+ if ('0' <= lo && lo <= '9') {
+ lo -= '0';
+ } else
+ if ('a' <= lo && lo <= 'f') {
+ lo -= ('a'-10);
+ } else
+ if ('A' <= lo && lo <= 'F') {
+ lo -= ('A' - 10);
+ }
+ result = lo + (16 * hi);
+ return result;
+}
+
+
+/* Decodes URL-Encoded strings (i.e. strings in which spaces are replaced by
+ * plusses, and escape characters are used)
+ */
+
+void decode_uri(gchar *decoded_uri, const gchar *encoded_uri)
+{
+ const gchar *encoded;
+ gchar *decoded;
+
+ encoded = encoded_uri;
+ decoded = decoded_uri;
+
+ while (*encoded) {
+ if (*encoded == '%') {
+ encoded++;
+ if (isxdigit(encoded[0])
+ && isxdigit(encoded[1])) {
+ *decoded = (gchar) axtoi(encoded);
+ decoded++;
+ encoded += 2;
+ }
+ }
+ else if (*encoded == '+') {
+ *decoded = ' ';
+ decoded++;
+ encoded++;
+ }
+ else {
+ *decoded = *encoded;
+ decoded++;
+ encoded++;
+ }
+ }
+
+ *decoded = '\0';
+}
+
+
gint open_uri(const gchar *uri, const gchar *cmdline)
{
static gchar *default_cmdline = "netscape -remote openURL(%s,raise)";
gchar buf[BUFFSIZE];
gchar *p;
-
+ gchar encoded_uri[BUFFSIZE];
+
g_return_val_if_fail(uri != NULL, -1);
+ /* an option to choose whether to use encode_uri or not ? */
+ encode_uri(encoded_uri, BUFFSIZE, uri);
+
if (cmdline &&
(p = strchr(cmdline, '%')) && *(p + 1) == 's' &&
!strchr(p + 2, '%'))
- g_snprintf(buf, sizeof(buf), cmdline, uri);
+ g_snprintf(buf, sizeof(buf), cmdline, encoded_uri);
else {
if (cmdline)
g_warning(_("Open URI command line is invalid: `%s'"),
cmdline);
- g_snprintf(buf, sizeof(buf), default_cmdline, uri);
+ g_snprintf(buf, sizeof(buf), default_cmdline, encoded_uri);
}
-
+
execute_command_line(buf, TRUE);
return 0;
fflush(log_fp);
}
}
+
+
+void * subject_table_lookup(GHashTable *subject_table, gchar * subject)
+{
+ if (subject == NULL)
+ subject = "";
+
+ if (g_strncasecmp(subject, "Re: ", 4) == 0)
+ return g_hash_table_lookup(subject_table, subject + 4);
+ else
+ return g_hash_table_lookup(subject_table, subject);
+}
+
+void subject_table_insert(GHashTable *subject_table, gchar * subject,
+ void * data)
+{
+ if (subject == NULL)
+ return;
+ if (* subject == 0)
+ return;
+ if (g_strcasecmp(subject, "Re:") == 0)
+ return;
+ if (g_strcasecmp(subject, "Re: ") == 0)
+ return;
+
+ if (g_strncasecmp(subject, "Re: ", 4) == 0)
+ g_hash_table_insert(subject_table, subject + 4, data);
+ else
+ g_hash_table_insert(subject_table, subject, data);
+}
+
+void subject_table_remove(GHashTable *subject_table, gchar * subject)
+{
+ if (subject == NULL)
+ return;
+
+ if (g_strncasecmp(subject, "Re: ", 4) == 0)
+ g_hash_table_remove(subject_table, subject + 4);
+ else
+ g_hash_table_remove(subject_table, subject);
+}
+
+gboolean subject_is_reply(const gchar *subject)
+{
+ /* XXX: just simply here so someone can handle really
+ * advanced Re: detection like "Re[4]", "ANTW:" or
+ * Re: Re: Re: Re: Re: Re: Re: Re:" stuff. */
+ if (subject == NULL) return FALSE;
+ else return 0 == g_strncasecmp(subject, "Re: ", 4);
+}