/*
* Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2001 Hiroyuki Yamamoto
+ * Copyright (C) 1999-2002 Hiroyuki Yamamoto
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
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);
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;
}
}
+void subst_chars(gchar *str, gchar *orig, gchar subst)
+{
+ register gchar *p = str;
+
+ while (*p) {
+ if (strchr(orig, *p) != NULL)
+ *p = subst;
+ p++;
+ }
+}
+
+void subst_for_filename(gchar *str)
+{
+ subst_chars(str, " \t\r\n\"/\\", '_');
+}
+
gboolean is_header_line(const gchar *str)
{
if (str[0] == ':') return FALSE;
return quote_level;
}
-GList *uri_list_extract_filenames(const gchar *uri_list)
-{
- GList *result = NULL;
- const gchar *p, *q;
- gchar *file;
-
- p = uri_list;
-
- while (p) {
- if (*p != '#') {
- while (isspace(*p)) p++;
- if (!strncmp(p, "file:", 5)) {
- p += 5;
- q = p;
- while (*q && *q != '\n' && *q != '\r') q++;
-
- if (q > p) {
- q--;
- while (q > p && isspace(*q)) q--;
- file = g_malloc(q - p + 2);
- strncpy(file, p, q - p + 1);
- file[q - p + 1] = '\0';
- result = g_list_append(result,file);
- }
- }
- }
- p = strchr(p, '\n');
- if (p) p++;
- }
-
- return result;
-}
-
gchar *strstr_with_skip_quote(const gchar *haystack, const gchar *needle)
{
register guint haystack_len, needle_len;
return str_array;
}
+GList *uri_list_extract_filenames(const gchar *uri_list)
+{
+ GList *result = NULL;
+ const gchar *p, *q;
+ gchar *file;
+
+ p = uri_list;
+
+ while (p) {
+ if (*p != '#') {
+ while (isspace(*p)) p++;
+ if (!strncmp(p, "file:", 5)) {
+ p += 5;
+ q = p;
+ while (*q && *q != '\n' && *q != '\r') q++;
+
+ if (q > p) {
+ q--;
+ while (q > p && isspace(*q)) q--;
+ file = g_malloc(q - p + 2);
+ strncpy(file, p, q - p + 1);
+ file[q - p + 1] = '\0';
+ result = g_list_append(result,file);
+ }
+ }
+ }
+ p = strchr(p, '\n');
+ if (p) p++;
+ }
+
+ return result;
+}
+
+#define HEX_TO_INT(val, hex) \
+{ \
+ gchar c = hex; \
+ \
+ if ('0' <= c && c <= '9') { \
+ val = c - '0'; \
+ } else if ('a' <= c && c <= 'f') { \
+ val = c - 'a' + 10; \
+ } else if ('A' <= c && c <= 'F') { \
+ val = c - 'A' + 10; \
+ } else { \
+ val = 0; \
+ } \
+}
+
/*
* We need this wrapper around g_get_home_dir(), so that
* we can fix some Windoze things here. Should be done in glibc of course
- * but as long as we are not able to do our own extensions to glibc, we do
+ * but as long as we are not able to do our own extensions to glibc, we do
* it here.
*/
gchar *get_home_dir(void)
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 s.st_size;
}
+off_t get_file_size_as_crlf(const gchar *file)
+{
+ FILE *fp;
+ off_t size = 0;
+ gchar buf[BUFFSIZE];
+
+ if ((fp = fopen(file, "r")) == NULL) {
+ FILE_OP_ERROR(file, "fopen");
+ return -1;
+ }
+
+ while (fgets(buf, sizeof(buf), fp) != NULL) {
+ strretchomp(buf);
+ size += strlen(buf) + 2;
+ }
+
+ if (ferror(fp)) {
+ FILE_OP_ERROR(file, "fgets");
+ size = -1;
+ }
+
+ fclose(fp);
+
+ return size;
+}
+
off_t get_left_file_size(FILE *fp)
{
glong pos;
return tmpfile();
}
+gchar *write_buffer_to_file(const gchar *buf, guint bufsize)
+{
+ FILE *fp;
+ gchar *tmp_file = NULL;
+
+ tmp_file = get_tmp_file();
+ fp = fopen(tmp_file, "w");
+ if (fp) {
+ fwrite(buf, 1, bufsize, fp);
+ fclose(fp);
+ }
+ else tmp_file = NULL;
+
+ return tmp_file;
+}
+
gint execute_async(gchar *const argv[])
{
pid_t pid;
gchar *p;
gchar c;
gint iustz;
- gint h, m;
+ gint offset;
time_t remoteoffset;
strncpy(zone3, zone, 3);
zone3[3] = '\0';
remoteoffset = 0;
- if (sscanf(zone, "%c%2d%2d", &c, &h, &m) == 3 &&
+ if (sscanf(zone, "%c%d", &c, &offset) == 2 &&
(c == '+' || c == '-')) {
- remoteoffset = ((h * 60) + m) * 60;
+ remoteoffset = ((offset / 100) * 60 + (offset % 100)) * 60;
if (c == '-')
remoteoffset = -remoteoffset;
} else if (!strncmp(zone, "UT" , 2) ||
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);
+}