/*
* Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2007 Hiroyuki Yamamoto and the Claws Mail team
+ * Copyright (C) 1999-2009 Hiroyuki Yamamoto and 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
- * the Free Software Foundation; either version 2 of the License, or
+ * the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
*/
#ifdef HAVE_CONFIG_H
#include <time.h>
#include <sys/stat.h>
+#ifdef G_OS_WIN32
+# include <w32lib.h>
+#endif
+
#include "procheader.h"
#include "procmsg.h"
#include "codeconv.h"
#define BUFFSIZE 8192
+static gchar monthstr[] = "JanFebMarAprMayJunJulAugSepOctNovDec";
+
typedef char *(*getlinefunc) (char *, size_t, void *);
typedef int (*peekcharfunc) (void *);
typedef int (*getcharfunc) (void *);
HeaderEntry hentry[])
{
return generic_get_one_field(buf, len, fp, hentry,
- (getlinefunc)fgets, (peekcharfunc)file_peekchar,
+ (getlinefunc)fgets_crlf, (peekcharfunc)file_peekchar,
TRUE);
}
static char *string_getline(char *buf, size_t len, char **str)
{
+ gboolean is_cr = FALSE;
+ gboolean last_was_cr = FALSE;
+
if (!*str || !**str)
return NULL;
- for (; **str && len > 1; --len)
- if ((*buf++ = *(*str)++) == '\n')
+ for (; **str && len > 1; --len) {
+ is_cr = (**str == '\r');
+ if ((*buf++ = *(*str)++) == '\n') {
break;
+ }
+ if (last_was_cr) {
+ *(--buf) = '\n';
+ buf++;
+ break;
+ }
+ last_was_cr = is_cr;
+ }
+
*buf = '\0';
return buf;
gint procheader_get_one_field_asis(gchar *buf, size_t len, FILE *fp)
{
return generic_get_one_field(buf, len, fp, NULL,
- (getlinefunc)fgets,
+ (getlinefunc)fgets_crlf,
(peekcharfunc)file_peekchar,
FALSE);
}
GPtrArray *headers;
Header *header;
- g_return_val_if_fail(fp != NULL, NULL);
+ cm_return_val_if_fail(fp != NULL, NULL);
headers = g_ptr_array_new();
while (procheader_get_one_field_asis(buf, sizeof(buf), fp) != -1) {
if ((header = procheader_parse_header(buf)) != NULL)
g_ptr_array_add(headers, header);
- /*
- if (*buf == ':') continue;
- for (p = buf; *p && *p != ' '; p++) {
- if (*p == ':') {
- header = g_new(Header, 1);
- header->name = g_strndup(buf, p - buf);
- p++;
- conv_unmime_header(tmp, sizeof(tmp), p, NULL);
- header->body = g_strdup(tmp);
-
- g_ptr_array_add(headers, header);
- break;
- }
- }
- */
}
return headers;
header->name = "From:"
header->body = "dinh@enseirb.fr"
*/
+static gboolean header_is_addr_field(const gchar *hdr)
+{
+ static char *addr_headers[] = {
+ "To:",
+ "Cc:",
+ "Bcc:",
+ "From:",
+ "Reply-To:",
+ "Followup-To:",
+ "Followup-and-Reply-To:",
+ "Disposition-Notification-To:",
+ "Return-Receipt-To:",
+ NULL};
+ int i;
+
+ if (!hdr)
+ return FALSE;
+
+ for (i = 0; addr_headers[i] != NULL; i++)
+ if (!strcasecmp(hdr, addr_headers[i]))
+ return FALSE;
+
+ return FALSE;
+}
Header * procheader_parse_header(gchar * buf)
{
gchar *p = buf;
Header * header;
+ gboolean addr_field = FALSE;
if ((*buf == ':') || (*buf == ' '))
return NULL;
if ((*p == ':') || (*p == ' ')) {
header = g_new(Header, 1);
header->name = g_strndup(buf, p - buf + 1);
+ addr_field = header_is_addr_field(header->name);
p++;
while (*p == ' ' || *p == '\t') p++;
- header->body = conv_unmime_header(p, NULL);
+ header->body = conv_unmime_header(p, NULL, addr_field);
return header;
}
}
FILE *fp;
MsgInfo *msginfo;
- if (stat(file, &s) < 0) {
+ if (g_stat(file, &s) < 0) {
FILE_OP_ERROR(file, "stat");
return NULL;
}
{"SC-Message-Size:",NULL, FALSE},
{NULL, NULL, FALSE}};
-HeaderEntry* procheader_get_headernames(gboolean full)
+static HeaderEntry* procheader_get_headernames(gboolean full)
{
return full ? hentry_full : hentry_short;
}
break;
case H_FROM:
if (msginfo->from) break;
- msginfo->from = conv_unmime_header(hp, NULL);
+ msginfo->from = conv_unmime_header(hp, NULL, TRUE);
msginfo->fromname = procheader_get_fromname(msginfo->from);
remove_return(msginfo->from);
remove_return(msginfo->fromname);
break;
case H_TO:
- tmp = conv_unmime_header(hp, NULL);
+ tmp = conv_unmime_header(hp, NULL, TRUE);
remove_return(tmp);
if (msginfo->to) {
p = msginfo->to;
g_free(tmp);
break;
case H_CC:
- tmp = conv_unmime_header(hp, NULL);
+ tmp = conv_unmime_header(hp, NULL, TRUE);
remove_return(tmp);
if (msginfo->cc) {
p = msginfo->cc;
break;
case H_SUBJECT:
if (msginfo->subject) break;
- msginfo->subject = conv_unmime_header(hp, NULL);
+ msginfo->subject = conv_unmime_header(hp, NULL, FALSE);
unfold_line(msginfo->subject);
break;
case H_MSG_ID:
gchar *zone)
{
gint result;
+ gint month_n;
+ gchar zone1[3];
+ gchar zone2[3];
+
+ if (str == NULL)
+ return -1;
result = sscanf(str, "%10s %d %9s %d %2d:%2d:%2d %5s",
weekday, day, month, year, hh, mm, ss, zone);
if (result == 8) return 0;
+ /* RFC2822 */
result = sscanf(str, "%3s,%d %9s %d %2d:%2d:%2d %5s",
weekday, day, month, year, hh, mm, ss, zone);
if (result == 8) return 0;
day, month, year, hh, mm);
if (result == 5) return 0;
+ /* RFC3339 subset */
+ *weekday = '\0';
+ result = sscanf(str, "%4d-%2d-%2d %2d:%2d:%2d+%2s:%2s",
+ year, &month_n, day, hh, mm, ss, zone1, zone2);
+ if (result == 8) {
+ if (1 <= month_n && month_n <= 12) {
+ strncpy2(month, monthstr+((month_n-1)*3), 4);
+ *zone = '+';
+ strncpy2(zone+1, zone1, 3);
+ strncpy2(zone+3, zone2, 3);
+ return 0;
+ }
+ }
+
+ /* RFC3339 subset */
+ *zone = '\0';
+ *weekday = '\0';
+ result = sscanf(str, "%4d-%2d-%2d %2d:%2d:%2d",
+ year, &month_n, day, hh, mm, ss);
+ if (result == 6) {
+ if (1 <= month_n && month_n <= 12) {
+ strncpy2(month, monthstr+((month_n-1)*3), 4);
+ return 0;
+ }
+ }
+
return -1;
}
*/
gboolean procheader_date_parse_to_tm(const gchar *src, struct tm *t, char *zone)
{
- static gchar monthstr[] = "JanFebMarAprMayJunJulAugSepOctNovDec";
gchar weekday[11];
gint day;
gchar month[10];
time_t procheader_date_parse(gchar *dest, const gchar *src, gint len)
{
- static gchar monthstr[] = "JanFebMarAprMayJunJulAugSepOctNovDec";
gchar weekday[11];
gint day;
gchar month[10];
gchar *default_format = "%y/%m/%d(%a) %H:%M";
gchar *str;
const gchar *src_codeset, *dest_codeset;
+ struct tm buf;
- lt = localtime(&timer);
+ if (timer > 0)
+ lt = localtime_r(&timer, &buf);
+ else {
+ time_t dummy = 1;
+ lt = localtime_r(&dummy, &buf);
+ }
if (prefs_common.date_format)
fast_strftime(dest, len, prefs_common.date_format, lt);
hentry[0].name = header;
- g_return_val_if_fail(msginfo != NULL, -1);
+ cm_return_val_if_fail(msginfo != NULL, -1);
file = procmsg_get_message_file_path(msginfo);
if ((fp = g_fopen(file, "rb")) == NULL) {
FILE_OP_ERROR(file, "fopen");
val = procheader_get_one_field(buf,len, fp, hentry);
if (fclose(fp) == EOF) {
FILE_OP_ERROR(file, "fclose");
- g_unlink(file);
+ claws_unlink(file);
g_free(file);
return -1;
}