2010-03-21 [pawel] 3.7.5cvs35
[claws.git] / src / common / utils.c
index 276bbb138638aeaf99f79fb6e91a57d072cdd86c..32baef37a012e14795eeb2b2cc1a3b6cc7624ae1 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];
@@ -1121,7 +1128,7 @@ static const gchar * line_has_quote_char_last(const gchar * str, const gchar *qu
        int i;
 
        if (quote_chars == NULL)
-               return FALSE;
+               return NULL;
 
        for (i = 0; i < strlen(quote_chars); i++) {
                tmp_pos = strrchr (str, quote_chars[i]);
@@ -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)
@@ -1544,7 +1551,7 @@ static gchar *decode_uri_gdup(const gchar *encoded_uri)
 }
 
 gint scan_mailto_url(const gchar *mailto, gchar **from, gchar **to, gchar **cc, gchar **bcc,
-                    gchar **subject, gchar **body, gchar ***attach)
+                    gchar **subject, gchar **body, gchar ***attach, gchar **inreplyto)
 {
        gchar *tmp_mailto;
        gchar *p;
@@ -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;
@@ -1652,6 +1659,9 @@ gint scan_mailto_url(const gchar *mailto, gchar **from, gchar **to, gchar **cc,
                                my_att[num_attach-1] = tmp;
                                my_att[num_attach] = NULL;
                        }
+               } else if (inreplyto && !*inreplyto &&
+                          !g_ascii_strcasecmp(field, "in-reply-to")) {
+                       *inreplyto = decode_uri_gdup(value);
                }
        }
 
@@ -1986,6 +1996,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)
 {
@@ -3666,18 +3686,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_;
@@ -3693,6 +3701,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
@@ -3712,7 +3731,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];
@@ -3770,6 +3791,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];
@@ -4249,7 +4272,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));