2012-05-11 [colin] 3.8.0cvs40
[claws.git] / src / common / utils.c
index 01467f6faf138df6de0801d052fbd4a81f0c9dcc..3b82ed01ff7c1aaea29bd9c62d909853e73d1f1a 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2009 Hiroyuki Yamamoto & The Claws Mail Team
+ * Copyright (C) 1999-2011 Hiroyuki Yamamoto & The Claws Mail Team
  *
  * 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
 
 #include <glib/gi18n.h>
 
+#ifdef USE_PTHREAD
+#include <pthread.h>
+#endif
+
 #include <stdio.h>
 #include <string.h>
 #include <ctype.h>
@@ -301,16 +305,6 @@ void ptr_array_free_strings(GPtrArray *array)
        }
 }
 
-gboolean str_find(const gchar *haystack, const gchar *needle)
-{
-       return strstr(haystack, needle) != NULL ? TRUE : FALSE;
-}
-
-gboolean str_case_find(const gchar *haystack, const gchar *needle)
-{
-       return strcasestr(haystack, needle) != NULL ? TRUE : FALSE;
-}
-
 gint to_number(const gchar *nstr)
 {
        register const gchar *p;
@@ -3538,9 +3532,7 @@ time_t tzoffset_sec(time_t *now)
 {
        struct tm gmt, *lt;
        gint off;
-#ifndef G_OS_WIN32
        struct tm buf1, buf2;
-#endif
 #ifdef G_OS_WIN32
        if (now && *now < 0)
                return 0;
@@ -3574,9 +3566,7 @@ gchar *tzoffset(time_t *now)
        struct tm gmt, *lt;
        gint off;
        gchar sign = '+';
-#ifndef G_OS_WIN32
        struct tm buf1, buf2;
-#endif
 #ifdef G_OS_WIN32
        if (now && *now < 0)
                return 0;
@@ -3614,10 +3604,8 @@ void get_rfc822_date(gchar *buf, gint len)
        time_t t;
        gchar day[4], mon[4];
        gint dd, hh, mm, ss, yyyy;
-#ifndef G_OS_WIN32
        struct tm buf1;
        gchar buf2[BUFFSIZE];
-#endif
 
        t = time(NULL);
        lt = localtime_r(&t, &buf1);
@@ -3846,29 +3834,23 @@ gchar *generate_msgid(gchar *buf, gint len, gchar *user_addr)
        struct tm *lt;
        time_t t;
        gchar *addr;
-#ifndef G_OS_WIN32
        struct tm buft;
-#endif
 
        t = time(NULL);
        lt = localtime_r(&t, &buft);
 
-       if (strcmp(buf, "") == 0) {
-               if (user_addr != NULL) {
-                       addr = g_strconcat(user_addr, "@", get_domain_name(), NULL);
-               }
-               else {
-                       addr = g_strconcat("@", get_domain_name(), NULL);
-               }
-       }
-       else {
-               if (user_addr != NULL) {
-                       addr = g_strconcat(user_addr, "@", buf, NULL);
-               }
-               else {
-                       addr = g_strconcat("@", buf, NULL);
-               }
-       }
+       if (user_addr != NULL)
+             addr = g_strdup_printf(".%s", user_addr);
+       else if (strlen(buf) != 0)
+             addr = g_strdup_printf("@%s", buf);
+       else
+             addr = g_strdup_printf("@%s", get_domain_name());
+
+       /* Replace all @ but the last one in addr, with underscores.
+        * RFC 2822 States that msg-id syntax only allows one @.
+        */
+       while (strchr(addr, '@') != NULL && strchr(addr, '@') != strrchr(addr, '@'))
+               *(strchr(addr, '@')) = '_';
 
        g_snprintf(buf, len, "%04d%02d%02d%02d%02d%02d.%08x%s",
                   lt->tm_year + 1900, lt->tm_mon + 1,
@@ -4862,9 +4844,11 @@ gboolean file_is_email (const gchar *filename)
               && fgets(buffer, sizeof (buffer), fp) > 0) {
                if (!strncmp(buffer, "From:", strlen("From:")))
                        score++;
-               if (!strncmp(buffer, "To:", strlen("To:")))
+               else if (!strncmp(buffer, "Date:", strlen("Date:")))
+                       score++;
+               else if (!strncmp(buffer, "Message-ID:", strlen("Message-ID:")))
                        score++;
-               if (!strncmp(buffer, "Subject:", strlen("Subject:")))
+               else if (!strncmp(buffer, "Subject:", strlen("Subject:")))
                        score++;
                i++;
        }