/*
* Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2007 Hiroyuki Yamamoto and the Claws Mail team
+ * Copyright (C) 1999-2014 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
#ifdef HAVE_CONFIG_H
# include "config.h"
+#include "claws-features.h"
#endif
#include <glib.h>
#include "procmsg.h"
#include "codeconv.h"
#include "prefs_common.h"
+#include "hooks.h"
#include "utils.h"
+#include "defs.h"
#define BUFFSIZE 8192
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;
+ gchar *p;
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;
}
}
MsgInfo *procheader_parse_file(const gchar *file, MsgFlags flags,
gboolean full, gboolean decrypted)
{
- struct stat s;
+ GStatBuf s;
FILE *fp;
MsgInfo *msginfo;
- if (stat(file, &s) < 0) {
+ if (g_stat(file, &s) < 0) {
FILE_OP_ERROR(file, "stat");
return NULL;
}
enum
{
- H_DATE = 0,
- H_FROM = 1,
- H_TO = 2,
- H_CC = 3,
- H_NEWSGROUPS = 4,
- H_SUBJECT = 5,
- H_MSG_ID = 6,
- H_REFERENCES = 7,
- H_IN_REPLY_TO = 8,
- H_CONTENT_TYPE = 9,
- H_SEEN = 10,
- H_STATUS = 11,
- H_X_STATUS = 12,
- H_FROM_SPACE = 13,
- H_SC_PLANNED_DOWNLOAD = 14,
- H_SC_MESSAGE_SIZE = 15,
- H_FACE = 16,
- H_X_FACE = 17,
- H_DISPOSITION_NOTIFICATION_TO = 18,
- H_RETURN_RECEIPT_TO = 19,
- H_SC_PARTIALLY_RETRIEVED = 20,
- H_SC_ACCOUNT_SERVER = 21,
- H_SC_ACCOUNT_LOGIN = 22,
- H_LIST_POST = 23,
- H_LIST_SUBSCRIBE = 24,
- H_LIST_UNSUBSCRIBE = 25,
- H_LIST_HELP = 26,
- H_LIST_ARCHIVE = 27,
- H_LIST_OWNER = 28,
+ H_DATE = 0,
+ H_FROM,
+ H_TO,
+ H_CC,
+ H_NEWSGROUPS,
+ H_SUBJECT,
+ H_MSG_ID,
+ H_REFERENCES,
+ H_IN_REPLY_TO,
+ H_CONTENT_TYPE,
+ H_SEEN,
+ H_STATUS,
+ H_FROM_SPACE,
+ H_SC_PLANNED_DOWNLOAD,
+ H_SC_MESSAGE_SIZE,
+ H_FACE,
+ H_X_FACE,
+ H_DISPOSITION_NOTIFICATION_TO,
+ H_RETURN_RECEIPT_TO,
+ H_SC_PARTIALLY_RETRIEVED,
+ H_SC_ACCOUNT_SERVER,
+ H_SC_ACCOUNT_LOGIN,
+ H_LIST_POST,
+ H_LIST_SUBSCRIBE,
+ H_LIST_UNSUBSCRIBE,
+ H_LIST_HELP,
+ H_LIST_ARCHIVE,
+ H_LIST_OWNER,
+ H_RESENT_FROM,
};
-static HeaderEntry hentry_full[] = {{"Date:", NULL, FALSE},
+static HeaderEntry hentry_full[] = {
+ {"Date:", NULL, FALSE},
{"From:", NULL, TRUE},
{"To:", NULL, TRUE},
{"Cc:", NULL, TRUE},
{"Content-Type:", NULL, FALSE},
{"Seen:", NULL, FALSE},
{"Status:", NULL, FALSE},
- {"X-Status:", NULL, FALSE},
{"From ", NULL, FALSE},
{"SC-Marked-For-Download:", NULL, FALSE},
{"SC-Message-Size:", NULL, FALSE},
{"List-Help:", NULL, TRUE},
{"List-Archive:", NULL, TRUE},
{"List-Owner:", NULL, TRUE},
+ {"Resent-From:", NULL, TRUE},
{NULL, NULL, FALSE}};
-static HeaderEntry hentry_short[] = {{"Date:", NULL, FALSE},
+static HeaderEntry hentry_short[] = {
+ {"Date:", NULL, FALSE},
{"From:", NULL, TRUE},
{"To:", NULL, TRUE},
{"Cc:", NULL, TRUE},
{"Content-Type:", NULL, FALSE},
{"Seen:", NULL, FALSE},
{"Status:", NULL, FALSE},
- {"X-Status:", NULL, FALSE},
{"From ", NULL, FALSE},
{"SC-Marked-For-Download:", NULL, FALSE},
{"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;
}
return parse_stream(fp, FALSE, flags, full, decrypted);
}
+static gboolean avatar_from_some_face(gpointer source, gpointer userdata)
+{
+ AvatarCaptureData *acd = (AvatarCaptureData *)source;
+
+ if (*(acd->content) == '\0') /* won't be null, but may be empty */
+ return FALSE;
+
+ if (!strcmp(acd->header, hentry_full[H_FACE].name)) {
+ debug_print("avatar_from_some_face: found 'Face' header\n");
+ procmsg_msginfo_add_avatar(acd->msginfo, AVATAR_FACE, acd->content);
+ }
+#if HAVE_LIBCOMPFACE
+ else if (!strcmp(acd->header, hentry_full[H_X_FACE].name)) {
+ debug_print("avatar_from_some_face: found 'X-Face' header\n");
+ procmsg_msginfo_add_avatar(acd->msginfo, AVATAR_XFACE, acd->content);
+ }
+#endif
+ return FALSE;
+}
+
+static guint avatar_hook_id = 0;
+
static MsgInfo *parse_stream(void *data, gboolean isstring, MsgFlags flags,
gboolean full, gboolean decrypted)
{
msginfo->inreplyto = NULL;
+ if (avatar_hook_id == 0 && (prefs_common.enable_avatars & AVATARS_ENABLE_CAPTURE)) {
+ avatar_hook_id = hooks_register_hook(AVATAR_HEADER_UPDATE_HOOKLIST, avatar_from_some_face, NULL);
+ } else if (avatar_hook_id != 0 && !(prefs_common.enable_avatars & AVATARS_ENABLE_CAPTURE)) {
+ hooks_unregister_hook(AVATAR_HEADER_UPDATE_HOOKLIST, avatar_hook_id);
+ avatar_hook_id = 0;
+ }
+
while ((hnum = get_one_field(buf, sizeof(buf), data, hentry))
!= -1) {
hp = buf + strlen(hentry[hnum].name);
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:
if (!g_ascii_strncasecmp(hp, "multipart/", 10))
MSG_SET_TMP_FLAGS(msginfo->flags, MSG_MULTIPART);
break;
-#ifdef ALLOW_HEADER_HINT
- case H_SEEN:
- /* mnews Seen header */
- MSG_UNSET_PERM_FLAGS(msginfo->flags, MSG_NEW|MSG_UNREAD);
- break;
-#endif
- case H_FACE:
- if (!msginfo->extradata)
- msginfo->extradata = g_new0(MsgInfoExtraData, 1);
- if (msginfo->extradata->face) break;
- msginfo->extradata->face = g_strdup(hp);
- break;
- case H_X_FACE:
- if (!msginfo->extradata)
- msginfo->extradata = g_new0(MsgInfoExtraData, 1);
- if (msginfo->extradata->xface) break;
- msginfo->extradata->xface = g_strdup(hp);
- break;
case H_DISPOSITION_NOTIFICATION_TO:
if (!msginfo->extradata)
msginfo->extradata = g_new0(MsgInfoExtraData, 1);
msginfo->planned_download = atoi(hp);
break;
/* end partial download infos */
-#ifdef ALLOW_HEADER_HINT
- case H_STATUS:
- if (strchr(hp, 'R') != NULL)
- MSG_UNSET_PERM_FLAGS(msginfo->flags, MSG_UNREAD);
- if (strchr(hp, 'O') != NULL)
- MSG_UNSET_PERM_FLAGS(msginfo->flags, MSG_NEW);
- if (strchr(hp, 'U') != NULL)
- MSG_SET_PERM_FLAGS(msginfo->flags, MSG_UNREAD);
- break;
- case H_X_STATUS:
- if (strchr(hp, 'D') != NULL)
- MSG_SET_PERM_FLAGS(msginfo->flags,
- MSG_REALLY_DELETED);
- if (strchr(hp, 'F') != NULL)
- MSG_SET_PERM_FLAGS(msginfo->flags, MSG_MARKED);
- if (strchr(hp, 'd') != NULL)
- MSG_SET_PERM_FLAGS(msginfo->flags, MSG_DELETED);
- if (strchr(hp, 'r') != NULL)
- MSG_SET_PERM_FLAGS(msginfo->flags, MSG_REPLIED);
- if (strchr(hp, 'f') != NULL)
- MSG_SET_PERM_FLAGS(msginfo->flags, MSG_FORWARDED);
- break;
-#endif
case H_FROM_SPACE:
if (msginfo->fromspace) break;
msginfo->fromspace = g_strdup(hp);
if (msginfo->extradata->list_owner) break;
msginfo->extradata->list_owner = g_strdup(hp);
break;
+ case H_RESENT_FROM:
+ if (!msginfo->extradata)
+ msginfo->extradata = g_new0(MsgInfoExtraData, 1);
+ if (msginfo->extradata->resent_from) break;
+ msginfo->extradata->resent_from = g_strdup(hp);
+ break;
/* end list infos */
default:
break;
}
+ /* to avoid performance penalty hooklist is invoked only for
+ headers known to be able to generate avatars */
+ if (hnum == H_FROM || hnum == H_X_FACE || hnum == H_FACE) {
+ AvatarCaptureData *acd = g_new0(AvatarCaptureData, 1);
+ /* no extra memory is wasted, hooks are expected to
+ take care of copying members when needed */
+ acd->msginfo = msginfo;
+ acd->header = hentry_full[hnum].name;
+ acd->content = hp;
+ hooks_invoke(AVATAR_HEADER_UPDATE_HOOKLIST, (gpointer)acd);
+ g_free(acd);
+ }
}
if (!msginfo->inreplyto && msginfo->references)
{
gint result;
gint month_n;
- gchar zone1[3];
- gchar zone2[3];
+ gint secfract;
+ gint zone1 = 0, zone2 = 0;
+ gchar offset_sign, zonestr[7];
+ gchar sep1;
- result = sscanf(str, "%10s %d %9s %d %2d:%2d:%2d %5s",
+ if (str == NULL)
+ return -1;
+
+ result = sscanf(str, "%10s %d %9s %d %2d:%2d:%2d %6s",
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",
+ result = sscanf(str, "%3s,%d %9s %d %2d:%2d:%2d %6s",
weekday, day, month, year, hh, mm, ss, zone);
if (result == 8) return 0;
- result = sscanf(str, "%d %9s %d %2d:%2d:%2d %5s",
+ result = sscanf(str, "%d %9s %d %2d:%2d:%2d %6s",
day, month, year, hh, mm, ss, zone);
if (result == 7) return 0;
if (result == 6) return 0;
*ss = 0;
- result = sscanf(str, "%10s %d %9s %d %2d:%2d %5s",
+ result = sscanf(str, "%10s %d %9s %d %2d:%2d %6s",
weekday, day, month, year, hh, mm, zone);
if (result == 7) 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) {
+
+ /* RFC3339 subset, with fraction of second */
+ result = sscanf(str, "%4d-%2d-%2d%c%2d:%2d:%2d.%d%6s",
+ year, &month_n, day, &sep1, hh, mm, ss, &secfract, zonestr);
+ if (result == 9
+ && (sep1 == 'T' || sep1 == 't' || sep1 == ' ')) {
+ if (month_n >= 1 && month_n <= 12) {
strncpy2(month, monthstr+((month_n-1)*3), 4);
- *zone = '+';
- strncpy2(zone+1, zone1, 3);
- strncpy2(zone+3, zone2, 3);
+ if (zonestr[0] == 'z' || zonestr[0] == 'Z') {
+ strcat(zone, "+00:00");
+ } else if (sscanf(zonestr, "%c%2d:%2d",
+ &offset_sign, &zone1, &zone2) == 3) {
+ strcat(zone, zonestr);
+ }
+ return 0;
+ }
+ }
+
+ /* RFC3339 subset, no fraction of second */
+ result = sscanf(str, "%4d-%2d-%2d%c%2d:%2d:%2d%6s",
+ year, &month_n, day, &sep1, hh, mm, ss, zonestr);
+ if (result == 8
+ && (sep1 == 'T' || sep1 == 't' || sep1 == ' ')) {
+ if (month_n >= 1 && month_n <= 12) {
+ strncpy2(month, monthstr+((month_n-1)*3), 4);
+ if (zonestr[0] == 'z' || zonestr[0] == 'Z') {
+ strcat(zone, "+00:00");
+ } else if (sscanf(zonestr, "%c%2d:%2d",
+ &offset_sign, &zone1, &zone2) == 3) {
+ strcat(zone, zonestr);
+ }
return 0;
}
}
- /* RFC3339 subset */
*zone = '\0';
- *weekday = '\0';
+
+ /* RFC3339 subset */
+ /* This particular "subset" is invalid, RFC requires the time offset */
result = sscanf(str, "%4d-%2d-%2d %2d:%2d:%2d",
year, &month_n, day, hh, mm, ss);
if (result == 6) {
if (procheader_scan_date_string(src, weekday, &day, month, &year,
&hh, &mm, &ss, zone) < 0) {
- g_warning("Invalid date: %s\n", src);
+ g_warning("Invalid date: %s", src);
return FALSE;
}
if ((p = strstr(monthstr, month)) != NULL)
dmonth = (gint)(p - monthstr) / 3 + 1;
else {
- g_warning("Invalid month: %s\n", month);
+ g_warning("Invalid month: %s", month);
dmonth = G_DATE_BAD_MONTH;
}
gchar month[10];
gint year;
gint hh, mm, ss;
- gchar zone[6];
+ gchar zone[7];
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) {
return 0;
}
- /* Y2K compliant :) */
- if (year < 1000) {
- if (year < 50)
- year += 2000;
- else
- year += 1900;
- }
-
month[3] = '\0';
for (p = monthstr; *p != '\0'; p += 3) {
if (!g_ascii_strncasecmp(p, month, 3)) {
}
}
+#ifdef G_OS_WIN32
+ GTimeZone *tz;
+ GDateTime *dt;
+
+ tz = g_time_zone_new(zone);
+ dt = g_date_time_new(tz, year, dmonth, day, hh, mm, ss);
+
+ timer = g_date_time_to_unix(dt);
+
+ g_date_time_unref(dt);
+ g_time_zone_unref(tz);
+
+#else
+ struct tm t;
+ time_t tz_offset;
+
+ /* Y2K compliant :) */
+ if (year < 1000) {
+ if (year < 50)
+ year += 2000;
+ else
+ year += 1900;
+ }
+
t.tm_sec = ss;
t.tm_min = mm;
t.tm_hour = hh;
if (dest)
procheader_date_get_localtime(dest, len, timer);
+#endif
return timer;
}
const gchar *src_codeset, *dest_codeset;
struct tm buf;
- lt = localtime_r(&timer, &buf);
+ 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;
}
return 0;
}
+
+HeaderEntry *procheader_entries_from_str(const gchar *str)
+{
+ HeaderEntry *entries = NULL, *he;
+ int numh = 0, i = 0;
+ gchar **names = NULL;
+ const gchar *s = str;
+
+ if (s == NULL) {
+ return NULL;
+ }
+ while (*s != '\0') {
+ if (*s == ' ') ++numh;
+ ++s;
+ }
+ if (numh == 0) {
+ return NULL;
+ }
+ entries = g_new0(HeaderEntry, numh + 1); /* room for last NULL */
+ s = str;
+ ++s; /* skip first space */
+ names = g_strsplit(s, " ", numh);
+ he = entries;
+ while (names[i]) {
+ he->name = g_strdup_printf("%s:", names[i]);
+ he->body = NULL;
+ he->unfold = FALSE;
+ ++i, ++he;
+ }
+ he->name = NULL;
+ g_strfreev(names);
+ return entries;
+}
+
+void procheader_entries_free (HeaderEntry *entries)
+{
+ if (entries != NULL) {
+ HeaderEntry *he = entries;
+ while (he->name != NULL) {
+ g_free(he->name);
+ if (he->body != NULL)
+ g_free(he->body);
+ ++he;
+ }
+ g_free(entries);
+ }
+}
+
+gboolean procheader_header_is_internal(const gchar *hdr_name)
+{
+ const gchar *internal_hdrs[] = {
+ "AF:", "NF:", "PS:", "SRH:", "SFN:", "DSR:", "MID:", "CFG:",
+ "PT:", "S:", "RQ:", "SSV:", "NSV:", "SSH:", "R:", "MAID:",
+ "SCF:", "RMID:", "FMID:", "NAID:",
+ "X-Claws-Account-Id:",
+ "X-Claws-Sign:",
+ "X-Claws-Encrypt:",
+ "X-Claws-Privacy-System:",
+ "X-Claws-Auto-Wrapping:",
+ "X-Claws-Auto-Indent:",
+ "X-Claws-End-Special-Headers:",
+ "X-Sylpheed-Account-Id:",
+ "X-Sylpheed-Sign:",
+ "X-Sylpheed-Encrypt:",
+ "X-Sylpheed-Privacy-System:",
+ "X-Sylpheed-End-Special-Headers:",
+ NULL
+ };
+ int i;
+
+ for (i = 0; internal_hdrs[i]; i++) {
+ if (!strcmp(hdr_name, internal_hdrs[i]))
+ return TRUE;
+ }
+ return FALSE;
+}