sync with 0.7.5cvs11
[claws.git] / src / procheader.c
index 4e450a2b66316ac9206ccf7ee818477998260212..93fc862c5f5f1806127f43d2daa4d4d7e99ce6c9 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2001 Hiroyuki Yamamoto
+ * Copyright (C) 1999-2002 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
@@ -191,7 +191,7 @@ GSList *procheader_get_header_list_from_file(const gchar *file)
        FILE *fp;
        GSList *hlist;
 
-       if ((fp = fopen(file, "r")) == NULL) {
+       if ((fp = fopen(file, "rb")) == NULL) {
                FILE_OP_ERROR(file, "fopen");
                return NULL;
        }
@@ -443,7 +443,7 @@ MsgInfo *procheader_parse(const gchar *file, MsgFlags flags,
        FILE *fp;
        MsgInfo *msginfo;
 
-       if ((fp = fopen(file, "r")) == NULL) {
+       if ((fp = fopen(file, "rb")) == NULL) {
                FILE_OP_ERROR(file, "fopen");
                return NULL;
        }
@@ -460,7 +460,7 @@ MsgInfo *procheader_parse(const gchar *file, MsgFlags flags,
  * so we're currently disabling setting any MsgFlags when detecting X-Seen,
  * Seen, X-Status, Status. See macro ALLOW_HEADER_HINT */  
 
-#define ALLOW_HEADER_HINT
+/* #define ALLOW_HEADER_HINT */
 
 MsgInfo *procheader_file_parse(FILE * fp, MsgFlags flags,
                               gboolean full, gboolean decrypted)
@@ -629,10 +629,12 @@ MsgInfo *procheader_file_parse(FILE * fp, MsgFlags flags,
                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:
@@ -700,6 +702,38 @@ gchar *procheader_get_fromname(const gchar *str)
        return name;
 }
 
+static gint procheader_scan_date_string(const gchar *str,
+                                       gchar *weekday, gint *day,
+                                       gchar *month, gint *year,
+                                       gint *hh, gint *mm, gint *ss,
+                                       gchar *zone)
+{
+       gint result;
+
+       result = sscanf(str, "%10s %d %9s %d %2d:%2d:%2d %5s",
+                       weekday, day, month, year, hh, mm, ss, zone);
+       if (result == 8) return 0;
+
+       result = sscanf(str, "%3s,%d %9s %d %2d:%2d:%2d %5s",
+                       weekday, day, month, year, hh, mm, ss, zone);
+       if (result == 8) return 0;
+
+       result = sscanf(str, "%d %9s %d %2d:%2d:%2d %5s",
+                       day, month, year, hh, mm, ss, zone);
+       if (result == 7) return 0;
+
+       *ss = 0;
+       result = sscanf(str, "%10s %d %9s %d %2d:%2d %5s",
+                       weekday, day, month, year, hh, mm, zone);
+       if (result == 7) return 0;
+
+       result = sscanf(str, "%d %9s %d %2d:%2d %5s",
+                       day, month, year, hh, mm, zone);
+       if (result == 6) return 0;
+
+       return -1;
+}
+
 time_t procheader_date_parse(gchar *dest, const gchar *src, gint len)
 {
        static gchar monthstr[] = "JanFebMarAprMayJunJulAugSepOctNovDec";
@@ -709,34 +743,17 @@ time_t procheader_date_parse(gchar *dest, const gchar *src, gint len)
        gint year;
        gint hh, mm, ss;
        gchar zone[6];
-       gint result;
        GDateMonth dmonth;
        struct tm t;
        gchar *p;
        time_t timer;
 
-       /* parsing date field... */
-       result = sscanf(src, "%10s %d %9s %d %2d:%2d:%2d %5s",
-                       weekday, &day, month, &year, &hh, &mm, &ss, zone);
-       if (result != 8) {
-               result = sscanf(src, "%d %9s %d %2d:%2d:%2d %5s",
-                               &day, month, &year, &hh, &mm, &ss, zone);
-               if (result != 7) {
-                       ss = 0;
-                       result = sscanf(src, "%10s %d %9s %d %2d:%2d %5s",
-                                       weekday, &day, month, &year, &hh, &mm, zone);
-                       if (result != 7) {
-                               result = sscanf(src, "%d %9s %d %2d:%2d %5s",
-                                               &day, month, &year, &hh, &mm,
-                                               zone);
-                               if (result != 6) {
-                                       g_warning("Invalid date: %s\n", src);
-                                       if (dest && len > 0)
-                                               strncpy2(dest, src, len);
-                                       return 0;
-                               }
-                       }
-               }
+       if (procheader_scan_date_string(src, weekday, &day, month, &year,
+                                       &hh, &mm, &ss, zone) < 0) {
+               g_warning("Invalid date: %s\n", src);
+               if (dest && len > 0)
+                       strncpy2(dest, src, len);
+               return 0;
        }
 
        /* Y2K compliant :) */
@@ -796,7 +813,7 @@ gint get_header_from_msginfo(MsgInfo *msginfo, gchar *buf, gint len,gchar *heade
        gint val;
        g_return_if_fail(msginfo != NULL);
        file = procmsg_get_message_file_path(msginfo);
-       if ((fp = fopen(file, "r")) == NULL) {
+       if ((fp = fopen(file, "rb")) == NULL) {
                FILE_OP_ERROR(file, "fopen");
                g_free(file);
                return;