fix encoding
[claws.git] / src / common / utils.c
index 03b74dc48576bc7ae845917209c2bbb0c2d51839..f4ec081fb6b12a21dbca0dc9b0ccd2acd5970cf2 100644 (file)
@@ -346,6 +346,13 @@ gchar *itos(gint n)
        d = (d*100) >> divisor;         \
 }
 
+
+/*!
+ * \brief Convert a given size in bytes in a human-readable string
+ *
+ * \param size  The size expressed in bytes to convert in string
+ * \return      The string that respresents the size in an human-readable way
+ */
 gchar *to_human_readable(goffset size)
 {
        static gchar str[14];
@@ -504,7 +511,7 @@ gint file_strip_crs(const gchar *file)
                goto unlinkout;
        }
        
-       if (rename_force(out, file) < 0)
+       if (move_file(out, file, TRUE) < 0)
                goto unlinkout;
        
        g_free(out);
@@ -1159,8 +1166,8 @@ gint get_quote_level(const gchar *str, const gchar *quote_chars)
                if (strchr(quote_chars, *p))
                        quote_level++;
                else if (*p != '-' && !g_ascii_isspace(*p) && p <= last_pos) {
-                       /* any characters are allowed except '-' and space */
-                       while (*p != '-'
+                       /* any characters are allowed except '-','<' and space */
+                       while (*p != '-' && *p != '<'
                               && !strchr(quote_chars, *p)
                               && !g_ascii_isspace(*p)
                               && p < last_pos)
@@ -1628,8 +1635,8 @@ gint scan_mailto_url(const gchar *mailto, gchar **from, gchar **to, gchar **cc,
                        *body = decode_uri_gdup(value);
                } else if (body && !*body && !g_ascii_strcasecmp(field, "insert")) {
                        gchar *tmp = decode_uri_gdup(value);
-                       if (!g_file_get_contents(value, body, NULL, NULL)) {
-                               g_error("Error: couldn't set insert file '%s' in body\n", value);
+                       if (!g_file_get_contents(tmp, body, NULL, NULL)) {
+                               g_warning("Error: couldn't set insert file '%s' in body\n", value);
                        }
                        g_free(tmp);
                        tmp = NULL;
@@ -1986,6 +1993,16 @@ const gchar *get_cert_file(void)
 }
 #endif
 
+/* Return the filepath of the claws-mail.desktop file */
+const gchar *get_desktop_file(void)
+{
+#ifdef DESKTOPFILEPATH
+  return DESKTOPFILEPATH;
+#else
+  return NULL;
+#endif
+}
+
 /* Return the default directory for Plugins. */
 const gchar *get_plugin_dir(void)
 {
@@ -3286,18 +3303,25 @@ static gint execute_sync(gchar *const argv[])
 
        cm_return_val_if_fail(argv != NULL && argv[0] != NULL, -1);
 
+#ifdef G_OS_UNIX
        if (g_spawn_sync(NULL, (gchar **)argv, NULL, G_SPAWN_SEARCH_PATH,
                         NULL, NULL, NULL, NULL, &status, NULL) == FALSE) {
                g_warning("Couldn't execute command: %s\n", argv[0]);
                return -1;
        }
 
-#ifdef G_OS_UNIX
        if (WIFEXITED(status))
                return WEXITSTATUS(status);
        else
                return -1;
 #else
+       if (g_spawn_sync(NULL, (gchar **)argv, NULL, G_SPAWN_SEARCH_PATH| 
+                        G_SPAWN_CHILD_INHERITS_STDIN|G_SPAWN_LEAVE_DESCRIPTORS_OPEN,
+                        NULL, NULL, NULL, NULL, &status, NULL) == FALSE) {
+               g_warning("Couldn't execute command: %s\n", argv[0]);
+               return -1;
+       }
+
        return status;
 #endif
 }
@@ -3659,18 +3683,6 @@ void subject_table_remove(GHashTable *subject_table, gchar * subject)
        g_hash_table_remove(subject_table, subject);
 }
 
-/*!
- *\brief       Check if a string is prefixed with known (combinations)
- *             of prefixes. The function assumes that each prefix
- *             is terminated by zero or exactly _one_ space.
- *
- *\param       str String to check for a prefixes
- *
- *\return      int Number of chars in the prefix that should be skipped
- *             for a "clean" subject line. If no prefix was found, 0
- *             is returned.
- */
 #ifndef G_OS_WIN32
 static regex_t u_regex;
 static gboolean u_init_;
@@ -3686,6 +3698,17 @@ void utils_free_regex(void)
 #endif
 }
 
+/*!
+ *\brief       Check if a string is prefixed with known (combinations)
+ *             of prefixes. The function assumes that each prefix
+ *             is terminated by zero or exactly _one_ space.
+ *
+ *\param       str String to check for a prefixes
+ *
+ *\return      int Number of chars in the prefix that should be skipped
+ *             for a "clean" subject line. If no prefix was found, 0
+ *             is returned.
+ */
 int subject_get_prefix_length(const gchar *subject)
 {
 #ifndef G_OS_WIN32
@@ -3705,7 +3728,9 @@ int subject_get_prefix_length(const gchar *subject)
                "Sv\\:",                        /* "Sv" (Norwegian) */
                "Vs\\:",                        /* "Vs" (Norwegian) */
                "Ad\\:",                        /* "Ad" (Norwegian) */
-               "\347\255\224\345\244\215\\:"   /* "Re" (Chinese, UTF-8) */
+               "\347\255\224\345\244\215\\:",  /* "Re" (Chinese, UTF-8) */
+               "R\303\251f\\. \\:",            /* "Réf. :" (French Lotus Notes) */
+               "Re \\:",                       /* "Re :" (French Yahoo Mail) */
                /* add more */
        };
        const int PREFIXES = sizeof prefixes / sizeof prefixes[0];
@@ -3763,6 +3788,8 @@ int subject_get_prefix_length(const gchar *subject)
                "sv:",                  /* "Sv" (Norwegian) */
                "vs:",                  /* "Vs" (Norwegian) */
                "ad:",                  /* "Ad" (Norwegian) */
+               "R\303\251f. :",        /* "Réf. :" (French Lotus Notes) */
+               "Re :",                 /* "Re :" (French Yahoo Mail) */
                /* add more */
        };
        const int PREFIXES = sizeof prefixes / sizeof prefixes[0];
@@ -3778,6 +3805,7 @@ int subject_get_prefix_length(const gchar *subject)
                                return len+1;
                        else
                                return len;
+               }
        }
        return 0;
 #endif
@@ -3807,7 +3835,7 @@ gint g_int_compare(gconstpointer a, gconstpointer b)
        return GPOINTER_TO_INT(a) - GPOINTER_TO_INT(b);
 }
 
-gchar *generate_msgid(gchar *buf, gint len)
+gchar *generate_msgid(gchar *buf, gint len, gchar *user_addr)
 {
        struct tm *lt;
        time_t t;
@@ -3820,10 +3848,20 @@ gchar *generate_msgid(gchar *buf, gint len)
        lt = localtime_r(&t, &buft);
 
        if (strcmp(buf, "") == 0) {
-               addr = g_strconcat("@", get_domain_name(), NULL);
+               if (user_addr != NULL) {
+                       addr = g_strconcat(user_addr, "@", get_domain_name(), NULL);
+               }
+               else {
+                       addr = g_strconcat("@", get_domain_name(), NULL);
+               }
        }
        else {
-               addr = g_strconcat("@", buf, NULL);
+               if (user_addr != NULL) {
+                       addr = g_strconcat(user_addr, "@", buf, NULL);
+               }
+               else {
+                       addr = g_strconcat("@", buf, NULL);
+               }
        }
 
        g_snprintf(buf, len, "%04d%02d%02d%02d%02d%02d.%08x%s",
@@ -4231,7 +4269,7 @@ gboolean get_uri_part(const gchar *start, const gchar *scanpos,
         * should pass some URI type to this function and decide on that whether
         * to perform punctuation stripping */
 
-#define IS_REAL_PUNCT(ch)      (g_ascii_ispunct(ch) && !strchr("/?=-)", ch))
+#define IS_REAL_PUNCT(ch)      (g_ascii_ispunct(ch) && !strchr("/?=-_)", ch))
 
        for (; ep_ - 1 > scanpos + 1 &&
               IS_REAL_PUNCT(*(ep_ - 1));