/*
* 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
FILE *fp;
GSList *hlist;
- if ((fp = fopen(file, "r")) == NULL) {
+ if ((fp = fopen(file, "rb")) == NULL) {
FILE_OP_ERROR(file, "fopen");
return NULL;
}
H_RETURN_RECEIPT_TO = 16
};
-MsgInfo *procheader_parse(const gchar *file, MsgFlags flags, gboolean full)
+MsgInfo *procheader_parse(const gchar *file, MsgFlags flags,
+ gboolean full, gboolean decrypted)
{
FILE *fp;
MsgInfo *msginfo;
- if ((fp = fopen(file, "r")) == NULL) {
+ if ((fp = fopen(file, "rb")) == NULL) {
FILE_OP_ERROR(file, "fopen");
return NULL;
}
- msginfo = procheader_file_parse(fp, flags, full);
+ msginfo = procheader_file_parse(fp, flags, full, decrypted);
fclose(fp);
* 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 full, gboolean decrypted)
{
static HeaderEntry hentry_full[] = {{"Date:", NULL, FALSE},
{"From:", NULL, TRUE},
else
MSG_SET_PERM_FLAGS(msginfo->flags, MSG_NEW | MSG_UNREAD);
+ if (decrypted)
+ MSG_UNSET_TMP_FLAGS(msginfo->flags, MSG_MIME);
+
msginfo->inreplyto = NULL;
while ((hnum = procheader_get_one_field(buf, sizeof(buf), fp, hentry))
msginfo->msgid = g_strdup(hp);
break;
case H_REFERENCES:
+ case H_IN_REPLY_TO:
if (!reference) {
msginfo->references = g_strdup(hp);
eliminate_parenthesis(hp, '(', ')');
}
}
break;
- case H_IN_REPLY_TO:
- if (!reference) {
- eliminate_parenthesis(hp, '(', ')');
- extract_parenthesis(hp, '<', '>');
- remove_space(hp);
- if (*hp != '\0')
- reference = g_strdup(hp);
- }
- break;
case H_CONTENT_TYPE:
- if (!strncasecmp(hp, "multipart", 9))
+ if (decrypted) {
+ if (!strncasecmp(hp, "multipart", 9) &&
+ strncasecmp(hp, "multipart/signed", 16)) {
+ MSG_SET_TMP_FLAGS(msginfo->flags,
+ MSG_MIME);
+ }
+ }
+ else if (!strncasecmp(hp, "multipart/encrypted", 19)) {
+ MSG_SET_TMP_FLAGS(msginfo->flags,
+ MSG_ENCRYPTED);
+ }
+ else if (!strncasecmp(hp, "multipart", 9))
MSG_SET_TMP_FLAGS(msginfo->flags, MSG_MIME);
break;
#ifdef ALLOW_HEADER_HINT
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:
{
gchar *tmp, *name;
- Xalloca(tmp, strlen(str) + 1, return NULL);
- strcpy(tmp, str);
+ Xstrdup_a(tmp, str, return NULL);
if (*tmp == '\"') {
extract_quote(tmp, '\"');
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";
- gchar weekday[4];
+ gchar weekday[11];
gint day;
- gchar month[4];
+ gchar month[10];
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, "%3s, %d %3s %d %2d:%2d:%2d %5s",
- weekday, &day, month, &year, &hh, &mm, &ss, zone);
- if (result != 8) {
- result = sscanf(src, "%d %3s %d %2d:%2d:%2d %5s",
- &day, month, &year, &hh, &mm, &ss, zone);
- if (result != 7) {
- ss = 0;
- result = sscanf(src, "%3s, %d %3s %d %2d:%2d %5s",
- weekday, &day, month, &year, &hh, &mm, zone);
- if (result != 7) {
- result = sscanf(src, "%d %3s %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 :) */
year += 1900;
}
+ month[3] = '\0';
if ((p = strstr(monthstr, month)) != NULL)
dmonth = (gint)(p - monthstr) / 3 + 1;
else {
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;