when using hide_timezone, convert time to UTC
[claws.git] / src / common / utils.c
index b13d09a67752c08d9049cedaa5b5f22e00194531..8236e848b6fe10a67ff51bbc3cb1bcb26ad15d3c 100644 (file)
@@ -1054,7 +1054,7 @@ void subst_for_filename(gchar *str)
        if (!str)
                return;
 #ifdef G_OS_WIN32
-       subst_chars(str, "\t\r\n\\/*:", '_');
+       subst_chars(str, "\t\r\n\\/*?:", '_');
 #else
        subst_chars(str, "\t\r\n\\/*", '_');
 #endif
@@ -1089,13 +1089,13 @@ static const gchar * line_has_quote_char_last(const gchar * str, const gchar *qu
        gchar * tmp_pos = NULL;
        int i;
 
-       if (quote_chars == NULL)
+       if (str == NULL || quote_chars == NULL)
                return NULL;
 
        for (i = 0; i < strlen(quote_chars); i++) {
-               tmp_pos = strrchr (str, quote_chars[i]);
+               tmp_pos = strrchr (str, quote_chars[i]);
                if(position == NULL
-                  || (tmp_pos != NULL && position <= tmp_pos) )
+                               || (tmp_pos != NULL && position <= tmp_pos) )
                        position = tmp_pos;
        }
        return position;
@@ -1178,13 +1178,13 @@ const gchar * line_has_quote_char(const gchar * str, const gchar *quote_chars)
        gchar * tmp_pos = NULL;
        int i;
 
-       if (quote_chars == NULL)
-               return FALSE;
+       if (str == NULL || quote_chars == NULL)
+               return NULL;
 
        for (i = 0; i < strlen(quote_chars); i++) {
-               tmp_pos = strchr (str,  quote_chars[i]);
+               tmp_pos = strchr (str, quote_chars[i]);
                if(position == NULL
-                  || (tmp_pos != NULL && position >= tmp_pos) )
+                               || (tmp_pos != NULL && position >= tmp_pos) )
                        position = tmp_pos;
        }
        return position;
@@ -2028,6 +2028,27 @@ const gchar *get_domain_name(void)
 
 off_t get_file_size(const gchar *file)
 {
+#ifdef G_OS_WIN32
+       GFile *f;
+       GFileInfo *fi;
+       GError *error = NULL;
+       goffset size;
+
+       f = g_file_new_for_path(file);
+       fi = g_file_query_info(f, "standard::size",
+                       G_FILE_QUERY_INFO_NONE, NULL, &error);
+       if (error != NULL) {
+               debug_print("get_file_size error: %s\n", error->message);
+               g_error_free(error);
+               g_object_unref(f);
+               return -1;
+       }
+       size = g_file_info_get_size(fi);
+       g_object_unref(fi);
+       g_object_unref(f);
+       return size;
+
+#else
        GStatBuf s;
 
        if (g_stat(file, &s) < 0) {
@@ -2036,6 +2057,7 @@ off_t get_file_size(const gchar *file)
        }
 
        return s.st_size;
+#endif
 }
 
 time_t get_file_mtime(const gchar *file)
@@ -3533,10 +3555,13 @@ static void _get_rfc822_date(gchar *buf, gint len, gboolean hidetz)
        gchar day[4], mon[4];
        gint dd, hh, mm, ss, yyyy;
        struct tm buf1;
-       gchar buf2[BUFFSIZE];
+       gchar buf2[RFC822_DATE_BUFFSIZE];
 
        t = time(NULL);
-       lt = localtime_r(&t, &buf1);
+       if (hidetz)
+               lt = gmtime_r(&t, &buf1);
+       else
+               lt = localtime_r(&t, &buf1);
 
        sscanf(asctime_r(lt, buf2), "%3s %3s %d %d:%d:%d %d\n",
               day, mon, &dd, &hh, &mm, &ss, &yyyy);
@@ -4085,7 +4110,7 @@ void replace_returns(gchar *str)
 }
 
 /* get_uri_part() - retrieves a URI starting from scanpos.
-                   Returns TRUE if succesful */
+                   Returns TRUE if successful */
 gboolean get_uri_part(const gchar *start, const gchar *scanpos,
                             const gchar **bp, const gchar **ep, gboolean hdr)
 {
@@ -4121,7 +4146,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));
@@ -4182,7 +4207,7 @@ static gboolean is_toplvl_domain(GHashTable *tab, const gchar *first, const gcha
        return g_hash_table_lookup(tab, buf) != NULL;
 }
 
-/* get_email_part() - retrieves an email address. Returns TRUE if succesful */
+/* get_email_part() - retrieves an email address. Returns TRUE if successful */
 gboolean get_email_part(const gchar *start, const gchar *scanpos,
                               const gchar **bp, const gchar **ep, gboolean hdr)
 {
@@ -4333,7 +4358,7 @@ search_again:
                ep_ += 3;
 
                /* go to matching '>' (or next non-rfc822 char, like \n) */
-               for (; *ep_ != '>' && *ep != '\0' && IS_RFC822_CHAR(*ep_); ep_++)
+               for (; *ep_ != '>' && *ep_ != '\0' && IS_RFC822_CHAR(*ep_); ep_++)
                        ;
 
                /* include the bracket */