inital gtk2 patch
[claws.git] / src / procheader.c
index 7811983b44b0d4d769ff56deb6ab53b63c3c1ae9..1c1a5d5a0b4f9c9daf54a0580b77578098a9bfbc 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2002 Hiroyuki Yamamoto
+ * Copyright (C) 1999-2003 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
@@ -486,44 +486,49 @@ enum
        H_RETURN_RECEIPT_TO = 16
 };
 
+static HeaderEntry hentry_full[] = {{"Date:",          NULL, FALSE},
+                                  {"From:",            NULL, TRUE},
+                                  {"To:",              NULL, TRUE},
+                                  {"Cc:",              NULL, TRUE},
+                                  {"Newsgroups:",      NULL, TRUE},
+                                  {"Subject:",         NULL, TRUE},
+                                  {"Message-Id:",      NULL, FALSE},
+                                  {"References:",      NULL, FALSE},
+                                  {"In-Reply-To:",     NULL, FALSE},
+                                  {"Content-Type:",    NULL, FALSE},
+                                  {"Seen:",            NULL, FALSE},
+                                  {"Status:",          NULL, FALSE},
+                                  {"X-Status:",        NULL, FALSE},
+                                  {"From ",            NULL, FALSE},
+                                  {"X-Face:",          NULL, FALSE},
+                                  {"Disposition-Notification-To:", NULL, FALSE},
+                                  {"Return-Receipt-To:", NULL, FALSE},
+                                  {NULL,               NULL, FALSE}};
+
+static HeaderEntry hentry_short[] = {{"Date:",         NULL, FALSE},
+                                   {"From:",           NULL, TRUE},
+                                   {"To:",             NULL, TRUE},
+                                   {"Cc:",             NULL, TRUE},
+                                   {"Newsgroups:",     NULL, TRUE},
+                                   {"Subject:",        NULL, TRUE},
+                                   {"Message-Id:",     NULL, FALSE},
+                                   {"References:",     NULL, FALSE},
+                                   {"In-Reply-To:",    NULL, FALSE},
+                                   {"Content-Type:",   NULL, FALSE},
+                                   {"Seen:",           NULL, FALSE},
+                                   {"Status:",         NULL, FALSE},
+                                   {"X-Status:",       NULL, FALSE},
+                                   {"From ",           NULL, FALSE},
+                                   {NULL,              NULL, FALSE}};
+
+HeaderEntry* procheader_get_headernames(gboolean full)
+{
+       return full ? hentry_full : hentry_short;
+}
+
 MsgInfo *procheader_parse_stream(FILE *fp, MsgFlags flags, gboolean full, 
                                 gboolean decrypted)
 {
-       static HeaderEntry hentry_full[] = {{"Date:",           NULL, FALSE},
-                                          {"From:",            NULL, TRUE},
-                                          {"To:",              NULL, TRUE},
-                                          {"Cc:",              NULL, TRUE},
-                                          {"Newsgroups:",      NULL, TRUE},
-                                          {"Subject:",         NULL, TRUE},
-                                          {"Message-Id:",      NULL, FALSE},
-                                          {"References:",      NULL, FALSE},
-                                          {"In-Reply-To:",     NULL, FALSE},
-                                          {"Content-Type:",    NULL, FALSE},
-                                          {"Seen:",            NULL, FALSE},
-                                          {"Status:",          NULL, FALSE},
-                                          {"X-Status:",        NULL, FALSE},
-                                          {"From ",            NULL, FALSE},
-                                          {"X-Face:",          NULL, FALSE},
-                                          {"Disposition-Notification-To:", NULL, FALSE},
-                                          {"Return-Receipt-To:", NULL, FALSE},
-                                          {NULL,               NULL, FALSE}};
-
-       static HeaderEntry hentry_short[] = {{"Date:",          NULL, FALSE},
-                                           {"From:",           NULL, TRUE},
-                                           {"To:",             NULL, TRUE},
-                                           {"Cc:",             NULL, TRUE},
-                                           {"Newsgroups:",     NULL, TRUE},
-                                           {"Subject:",        NULL, TRUE},
-                                           {"Message-Id:",     NULL, FALSE},
-                                           {"References:",     NULL, FALSE},
-                                           {"In-Reply-To:",    NULL, FALSE},
-                                           {"Content-Type:",   NULL, FALSE},
-                                           {"Seen:",           NULL, FALSE},
-                                           {"Status:",         NULL, FALSE},
-                                           {"X-Status:",       NULL, FALSE},
-                                           {"From ",           NULL, FALSE},
-                                           {NULL,              NULL, FALSE}};
-
        MsgInfo *msginfo;
        gchar buf[BUFFSIZE], tmp[BUFFSIZE];
        gchar *reference = NULL;
@@ -532,7 +537,7 @@ MsgInfo *procheader_parse_stream(FILE *fp, MsgFlags flags, gboolean full,
        HeaderEntry *hentry;
        gint hnum;
 
-       hentry = full ? hentry_full : hentry_short;
+       hentry = procheader_get_headernames(full);
 
        if (MSG_IS_QUEUED(flags) || MSG_IS_DRAFT(flags)) {
                while (fgets(buf, sizeof(buf), fp) != NULL)
@@ -626,10 +631,14 @@ MsgInfo *procheader_parse_stream(FILE *fp, MsgFlags flags, gboolean full,
                        break;
                case H_CONTENT_TYPE:
                        if (decrypted) {
-                               if (!strncasecmp(hp, "multipart", 9) &&
-                                   strncasecmp(hp, "multipart/signed", 16)) {
-                                       MSG_SET_TMP_FLAGS(msginfo->flags,
+                               if (!strncasecmp(hp, "multipart", 9)) {
+                                       if (strncasecmp(hp, "multipart/signed", 16)) {
+                                               MSG_SET_TMP_FLAGS(msginfo->flags,
+                                                         MSG_MIME);
+                                       } else {
+                                               MSG_SET_TMP_FLAGS(msginfo->flags,
                                                          MSG_SIGNED);
+                                       }
                                }
                        }
                        else if (!strncasecmp(hp, "multipart/encrypted", 19)) {
@@ -656,12 +665,10 @@ MsgInfo *procheader_parse_stream(FILE *fp, MsgFlags flags, gboolean full,
                case H_DISPOSITION_NOTIFICATION_TO:
                        if (msginfo->dispositionnotificationto) break;
                        msginfo->dispositionnotificationto = g_strdup(hp);
-                       MSG_SET_PERM_FLAGS(msginfo->flags, MSG_RETRCPT_PENDING);        
                        break;
                case H_RETURN_RECEIPT_TO:
                        if (msginfo->returnreceiptto) break;
                        msginfo->returnreceiptto = g_strdup(hp);
-                       MSG_SET_PERM_FLAGS(msginfo->flags, MSG_RETRCPT_PENDING);        
                        break;
 #ifdef ALLOW_HEADER_HINT                       
                case H_STATUS:
@@ -749,6 +756,11 @@ static gint procheader_scan_date_string(const gchar *str,
                        day, month, year, hh, mm, ss, zone);
        if (result == 7) return 0;
 
+       *zone = '\0';
+       result = sscanf(str, "%10s %d %9s %d %2d:%2d:%2d",
+                       weekday, day, month, year, hh, mm, ss);
+       if (result == 7) return 0;
+
        *ss = 0;
        result = sscanf(str, "%10s %d %9s %d %2d:%2d %5s",
                        weekday, day, month, year, hh, mm, zone);
@@ -827,10 +839,11 @@ time_t procheader_date_parse(gchar *dest, const gchar *src, gint len)
        gint year;
        gint hh, mm, ss;
        gchar zone[6];
-       GDateMonth dmonth;
+       GDateMonth dmonth = G_DATE_BAD_MONTH;
        struct tm t;
        gchar *p;
        time_t timer;
+       time_t tz_offset;
 
        if (procheader_scan_date_string(src, weekday, &day, month, &year,
                                        &hh, &mm, &ss, zone) < 0) {
@@ -841,20 +854,22 @@ time_t procheader_date_parse(gchar *dest, const gchar *src, gint len)
        }
 
        /* Y2K compliant :) */
-       if (year < 100) {
-               if (year < 70)
+       if (year < 1000) {
+               if (year < 50)
                        year += 2000;
                else
                        year += 1900;
        }
 
        month[3] = '\0';
-       if ((p = strstr(monthstr, month)) != NULL)
-               dmonth = (gint)(p - monthstr) / 3 + 1;
-       else {
-               g_warning("Invalid month: %s\n", month);
-               dmonth = G_DATE_BAD_MONTH;
+       for (p = monthstr; *p != '\0'; p += 3) {
+               if (!strncasecmp(p, month, 3)) {
+                       dmonth = (gint)(p - monthstr) / 3 + 1;
+                       break;
+               }
        }
+       if (*p == '\0')
+               g_warning("Invalid month: %s\n", month);
 
        t.tm_sec = ss;
        t.tm_min = mm;
@@ -867,7 +882,9 @@ time_t procheader_date_parse(gchar *dest, const gchar *src, gint len)
        t.tm_isdst = -1;
 
        timer = mktime(&t);
-       timer += tzoffset_sec(&timer) - remote_tzoffset_sec(zone);
+       tz_offset = remote_tzoffset_sec(zone);
+       if (tz_offset != -1)
+               timer += tzoffset_sec(&timer) - tz_offset;
 
        if (dest)
                procheader_date_get_localtime(dest, len, timer);
@@ -886,6 +903,23 @@ void procheader_date_get_localtime(gchar *dest, gint len, const time_t timer)
                strftime(dest, len, prefs_common.date_format, lt);
        else
                strftime(dest, len, default_format, lt);
+
+#warning FIXME_GTK2
+#if 1
+       {
+               gchar *str;
+               const gchar *src_codeset, *dest_codeset;
+
+               src_codeset = conv_get_current_charset_str();
+               dest_codeset = CS_UTF_8;
+               str = conv_codeset_strdup(dest, src_codeset, dest_codeset);
+               if (str) {
+                       g_snprintf(dest, len, "%s", str);
+                       strncpy2(dest, str, len);
+                       g_free(str);
+               }
+       }
+#endif
 }
 
 gint get_header_from_msginfo(MsgInfo *msginfo, gchar *buf, gint len, gchar *header)