0.8.10claws34
[claws.git] / src / procheader.c
index 63c8ffbb3e50d16114d4549ff79cf4ea0f7599e7..9bd66a78afd6140ceecf201209310b297c57806c 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
@@ -398,7 +398,10 @@ Header * procheader_parse_header(gchar * buf)
                        p++;
                        while (*p == ' ' || *p == '\t') p++;
                        conv_unmime_header(tmp, sizeof(tmp), p, NULL);
-                       header->body = g_strdup(tmp);
+                       if(tmp == NULL) 
+                               header->body = g_strdup(p);
+                       else    
+                               header->body = g_strdup(tmp);
                        return header;
                }
        }
@@ -483,53 +486,58 @@ 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}};
+
+const 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;
        gchar *p;
        gchar *hp;
-       HeaderEntry *hentry;
+       const 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)
@@ -593,7 +601,7 @@ MsgInfo *procheader_parse_stream(FILE *fp, MsgFlags flags, gboolean full,
                                        g_strconcat(p, ",", hp, NULL);
                                g_free(p);
                        } else
-                               msginfo->newsgroups = g_strdup(buf + 12);
+                               msginfo->newsgroups = g_strdup(hp);
                        break;
                case H_SUBJECT:
                        if (msginfo->subject) break;
@@ -623,16 +631,24 @@ 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)) {
                                MSG_SET_TMP_FLAGS(msginfo->flags,
                                                  MSG_ENCRYPTED);
-                       }
+                       } 
+                       else if (!strncasecmp(hp, "multipart", 9) &&
+                                  !strncasecmp(hp, "multipart/signed", 16)) {
+                               MSG_SET_TMP_FLAGS(msginfo->flags, MSG_SIGNED);
+                       } 
                        else if (!strncasecmp(hp, "multipart", 9))
                                MSG_SET_TMP_FLAGS(msginfo->flags, MSG_MIME);
                        break;
@@ -820,7 +836,7 @@ 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;
@@ -842,12 +858,14 @@ time_t procheader_date_parse(gchar *dest, const gchar *src, gint len)
        }
 
        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;
@@ -881,12 +899,12 @@ void procheader_date_get_localtime(gchar *dest, gint len, const time_t timer)
                strftime(dest, len, default_format, lt);
 }
 
-gint get_header_from_msginfo(MsgInfo *msginfo, gchar *buf, gint len,gchar *header)
+gint get_header_from_msginfo(MsgInfo *msginfo, gchar *buf, gint len, gchar *header)
 {
        gchar *file;
        FILE *fp;
-       HeaderEntry hentry[]={{header,NULL,TRUE},
-                              {NULL,NULL,FALSE}};
+       HeaderEntry hentry[]={ { header, NULL, TRUE  },
+                               { NULL,   NULL, FALSE } };
        gint val;
        
        g_return_val_if_fail(msginfo != NULL, -1);
@@ -896,12 +914,15 @@ gint get_header_from_msginfo(MsgInfo *msginfo, gchar *buf, gint len,gchar *heade
                g_free(file);
                return -1;
        }
-       val=procheader_get_one_field(buf,len, fp, hentry);
+       val = procheader_get_one_field(buf,len, fp, hentry);
        if (fclose(fp) == EOF) {
                FILE_OP_ERROR(file, "fclose");
                unlink(file);
+               g_free(file);
                return -1;
        }
+
+       g_free(file);
         if (val == -1)
                return -1;