Commit ef6caf30 authored by Milan Crha's avatar Milan Crha
Browse files

Bug #633185 - Can't handle Birthdays before 01/01/1970

parent 847c41a3
......@@ -451,19 +451,14 @@ mapi_book_write_props (ExchangeMapiConnection *conn, mapi_id_t fid, TALLOC_CTX *
/* BDAY AND ANNV */
if (e_contact_get (mcd->contact, E_CONTACT_BIRTH_DATE)) {
EContactDate *date = e_contact_get (mcd->contact, E_CONTACT_BIRTH_DATE);
struct tm tmtime;
time_t lt;
NTTIME nt;
struct tm tmtime = { 0 };
struct FILETIME t;
tmtime.tm_mday = date->day;
tmtime.tm_mon = date->month - 1;
tmtime.tm_year = date->year - 1900;
lt = mktime (&tmtime);
unix_to_nt_time (&nt, lt);
t.dwLowDateTime = (nt << 32) >> 32;
t.dwHighDateTime = (nt >> 32);
exchange_mapi_util_time_t_to_filetime (mktime (&tmtime) + (24 * 60 * 60), &t);
if (!exchange_mapi_utils_add_spropvalue (mem_ctx, values, n_values, PR_BIRTHDAY, &t))
return FALSE;
......@@ -471,19 +466,14 @@ mapi_book_write_props (ExchangeMapiConnection *conn, mapi_id_t fid, TALLOC_CTX *
if (e_contact_get (mcd->contact, E_CONTACT_ANNIVERSARY)) {
EContactDate *date = e_contact_get (mcd->contact, E_CONTACT_ANNIVERSARY);
struct tm tmtime;
time_t lt;
NTTIME nt;
struct tm tmtime = { 0 };
struct FILETIME t;
tmtime.tm_mday = date->day;
tmtime.tm_mon = date->month - 1;
tmtime.tm_year = date->year - 1900;
lt = mktime (&tmtime);
unix_to_nt_time (&nt, lt);
t.dwLowDateTime = (nt << 32) >> 32;
t.dwHighDateTime = (nt >> 32);
exchange_mapi_util_time_t_to_filetime (mktime (&tmtime) + (24 * 60 * 60), &t);
if (!exchange_mapi_utils_add_spropvalue (mem_ctx, values, n_values, PR_WEDDING_ANNIVERSARY, &t))
return FALSE;
......
......@@ -1914,15 +1914,10 @@ mapi_book_utils_contact_from_props (ExchangeMapiConnection *conn, mapi_id_t fid,
e_contact_set (contact, mappings[i].field_id, value);
} else if (contact_type == ELEMENT_TYPE_SIMPLE) {
if (value && mappings[i].element_type == PT_SYSTIME) {
struct FILETIME *t = value;
time_t time;
NTTIME nt;
const struct FILETIME *t = value;
gchar buff[129];
time_t time = exchange_mapi_util_filetime_to_time_t (t);
nt = t->dwHighDateTime;
nt = nt << 32;
nt |= t->dwLowDateTime;
time = nt_time_to_unix (nt);
e_contact_set (contact, mappings[i].field_id, ctime_r (&time, buff));
}
} else if (contact_type == ELEMENT_TYPE_COMPLEX) {
......@@ -1934,18 +1929,15 @@ mapi_book_utils_contact_from_props (ExchangeMapiConnection *conn, mapi_id_t fid,
g_list_free (list);
} else if (mappings[i].field_id == E_CONTACT_BIRTH_DATE
|| mappings[i].field_id == E_CONTACT_ANNIVERSARY) {
struct FILETIME *t = value;
const struct FILETIME *t = value;
time_t time;
NTTIME nt;
struct tm * tmtime;
if (value) {
EContactDate date = {0};
nt = t->dwHighDateTime;
nt = nt << 32;
nt |= t->dwLowDateTime;
time = nt_time_to_unix (nt);
time = exchange_mapi_util_filetime_to_time_t (t);
tmtime = gmtime (&time);
//FIXME: Move to new libmapi api to get string dates.
date.day = tmtime->tm_mday;
date.month = tmtime->tm_mon + 1;
date.year = tmtime->tm_year + 1900;
......
......@@ -158,7 +158,6 @@ fetch_items_summary_cb (FetchItemsCallbackData *item_data, gpointer data)
struct timeval item_modification_time = { 0 };
struct timeval fi_data_mod_time = { 0 };
guint32 j = 0;
NTTIME ntdate;
MailItem *item = g_new0(MailItem , 1);
......@@ -197,17 +196,12 @@ fetch_items_summary_cb (FetchItemsCallbackData *item_data, gpointer data)
/* item->header.from = camel_internet_address_format_address (from_name, from_email); */
if (delivery_date) {
ntdate = delivery_date->dwHighDateTime;
ntdate = ntdate << 32;
ntdate |= delivery_date->dwLowDateTime;
item->header.recieved_time = nt_time_to_unix(ntdate);
item->header.recieved_time = exchange_mapi_util_filetime_to_time_t (delivery_date);
}
if (last_modification_time) {
ntdate = last_modification_time->dwHighDateTime;
ntdate = ntdate << 32;
ntdate |= last_modification_time->dwLowDateTime;
nttime_to_timeval (&item_modification_time, ntdate);
item_modification_time.tv_sec = exchange_mapi_util_filetime_to_time_t (last_modification_time);
item_modification_time.tv_usec = 0;
}
fi_data_mod_time.tv_sec = fi_data->last_modification_time.tv_sec;
......
......@@ -477,11 +477,8 @@ camel_mapi_utils_create_item_build_props (ExchangeMapiConnection *conn, mapi_id_
if (item->header.recieved_time != 0) {
struct FILETIME msg_date = { 0 };
NTTIME nttime = 0;
unix_to_nt_time (&nttime, item->header.recieved_time);
msg_date.dwHighDateTime = nttime >> 32;
msg_date.dwLowDateTime = nttime & 0xFFFFFFFF;
exchange_mapi_util_time_t_to_filetime (item->header.recieved_time, &msg_date);
set_value (PR_MESSAGE_DELIVERY_TIME, &msg_date);
}
......
......@@ -1243,7 +1243,7 @@ exchange_mapi_cal_utils_write_props_cb (ExchangeMapiConnection *conn, mapi_id_t
struct icaltimetype dtstart, dtend, utc_dtstart, utc_dtend;
const icaltimezone *utc_zone;
const gchar *dtstart_tz_location, *dtend_tz_location, *text = NULL;
struct timeval t;
time_t tt;
g_return_val_if_fail (conn != NULL, FALSE);
g_return_val_if_fail (mem_ctx != NULL, FALSE);
......@@ -1279,12 +1279,8 @@ exchange_mapi_cal_utils_write_props_cb (ExchangeMapiConnection *conn, mapi_id_t
#define set_datetime_value(hex, dtval) G_STMT_START { \
struct FILETIME filetime; \
NTTIME nttime; \
\
nttime = timeval_to_nttime(dtval); \
\
filetime.dwLowDateTime = (nttime << 32) >> 32; \
filetime.dwHighDateTime = nttime >> 32; \
exchange_mapi_util_time_t_to_filetime (dtval, &filetime); \
\
if (!exchange_mapi_utils_add_spropvalue (mem_ctx, values, n_values, hex, &filetime)) \
return FALSE; \
......@@ -1292,12 +1288,8 @@ exchange_mapi_cal_utils_write_props_cb (ExchangeMapiConnection *conn, mapi_id_t
#define set_named_datetime_value(named_id, dtval) G_STMT_START { \
struct FILETIME filetime; \
NTTIME nttime; \
\
nttime = timeval_to_nttime(dtval); \
\
filetime.dwLowDateTime = (nttime << 32) >> 32; \
filetime.dwHighDateTime = nttime >> 32; \
exchange_mapi_util_time_t_to_filetime (dtval, &filetime); \
\
if (!exchange_mapi_utils_add_spropvalue_named_id (conn, fid, mem_ctx, values, n_values, named_id, &filetime)) \
return FALSE; \
......@@ -1397,13 +1389,11 @@ exchange_mapi_cal_utils_write_props_cb (ExchangeMapiConnection *conn, mapi_id_t
}
set_named_value (PidLidReminderSet, &b);
set_named_value (PidLidReminderDelta, &flag32);
t.tv_sec = icaltime_as_timet (utc_dtstart);
t.tv_usec = 0;
set_named_datetime_value (PidLidReminderTime, &t);
t.tv_sec = icaltime_as_timet (utc_dtstart) - (flag32 * SECS_IN_MINUTE);
t.tv_usec = 0;
tt = icaltime_as_timet (utc_dtstart);
set_named_datetime_value (PidLidReminderTime, tt);
tt = icaltime_as_timet (utc_dtstart) - (flag32 * SECS_IN_MINUTE);
/* ReminderNextTime: FIXME for recurrence */
set_named_datetime_value (PidLidReminderSignalTime, &t);
set_named_datetime_value (PidLidReminderSignalTime, tt);
/* Sensitivity, Private */
flag32 = olNormal; /* default */
......@@ -1416,15 +1406,13 @@ exchange_mapi_cal_utils_write_props_cb (ExchangeMapiConnection *conn, mapi_id_t
set_value (PR_SENSITIVITY, &flag32);
set_named_value (PidLidPrivate, &b);
t.tv_sec = icaltime_as_timet (utc_dtstart);
t.tv_usec = 0;
set_named_datetime_value (PidLidCommonStart, &t);
set_datetime_value (PR_START_DATE, &t);
tt = icaltime_as_timet (utc_dtstart);
set_named_datetime_value (PidLidCommonStart, tt);
set_datetime_value (PR_START_DATE, tt);
t.tv_sec = icaltime_as_timet (utc_dtend);
t.tv_usec = 0;
set_named_datetime_value (PidLidCommonEnd, &t);
set_datetime_value (PR_END_DATE, &t);
tt = icaltime_as_timet (utc_dtend);
set_named_datetime_value (PidLidCommonEnd, tt);
set_datetime_value (PR_END_DATE, tt);
b = 1;
set_value (PR_RESPONSE_REQUESTED, &b);
......@@ -1471,11 +1459,10 @@ exchange_mapi_cal_utils_write_props_cb (ExchangeMapiConnection *conn, mapi_id_t
set_named_value (PidLidAutoFillLocation, &b);
/* Start */
t.tv_sec = icaltime_as_timet (utc_dtstart);
t.tv_usec = 0;
set_named_datetime_value (PidLidAppointmentStartWhole, &t);
tt = icaltime_as_timet (utc_dtstart);
set_named_datetime_value (PidLidAppointmentStartWhole, tt);
/* FIXME: for recurrence */
set_named_datetime_value (PidLidClipStart, &t);
set_named_datetime_value (PidLidClipStart, tt);
/* Start TZ */
mapi_tzid = exchange_mapi_cal_tz_util_get_mapi_equivalent ((dtstart_tz_location && *dtstart_tz_location) ? dtstart_tz_location : "UTC");
......@@ -1485,11 +1472,10 @@ exchange_mapi_cal_utils_write_props_cb (ExchangeMapiConnection *conn, mapi_id_t
}
/* End */
t.tv_sec = icaltime_as_timet (utc_dtend);
t.tv_usec = 0;
set_named_datetime_value (PidLidAppointmentEndWhole, &t);
tt = icaltime_as_timet (utc_dtend);
set_named_datetime_value (PidLidAppointmentEndWhole, tt);
/* FIXME: for recurrence */
set_named_datetime_value (PidLidClipEnd, &t);
set_named_datetime_value (PidLidClipEnd, tt);
/* End TZ */
mapi_tzid = exchange_mapi_cal_tz_util_get_mapi_equivalent ((dtend_tz_location && *dtend_tz_location) ? dtend_tz_location : "UTC");
......@@ -1730,25 +1716,22 @@ exchange_mapi_cal_utils_write_props_cb (ExchangeMapiConnection *conn, mapi_id_t
completed = icalproperty_get_completed (prop);
completed.hour = completed.minute = completed.second = 0; completed.is_date = completed.is_utc = 1;
t.tv_sec = icaltime_as_timet (completed);
t.tv_usec = 0;
set_named_datetime_value (PidLidTaskDateCompleted, &t);
tt = icaltime_as_timet (completed);
set_named_datetime_value (PidLidTaskDateCompleted, tt);
}
/* Start */
dtstart.hour = dtstart.minute = dtstart.second = 0; dtstart.is_date = dtstart.is_utc = 1;
t.tv_sec = icaltime_as_timet (dtstart);
t.tv_usec = 0;
tt = icaltime_as_timet (dtstart);
if (!icaltime_is_null_time (dtstart)) {
set_named_datetime_value (PidLidTaskStartDate, &t);
set_named_datetime_value (PidLidTaskStartDate, tt);
}
/* Due */
dtend.hour = dtend.minute = dtend.second = 0; dtend.is_date = dtend.is_utc = 1;
t.tv_sec = icaltime_as_timet (dtend);
t.tv_usec = 0;
tt = icaltime_as_timet (dtend);
if (!icaltime_is_null_time (dtend)) {
set_named_datetime_value (PidLidTaskDueDate, &t);
set_named_datetime_value (PidLidTaskDueDate, tt);
}
/* FIXME: Evolution does not support recurring tasks */
......
......@@ -135,12 +135,7 @@ fetch_props_to_mail_item_cb (FetchItemsCallbackData *item_data, gpointer data)
}
if (delivery_date) {
NTTIME ntdate = { 0 };
ntdate = delivery_date->dwHighDateTime;
ntdate = ntdate << 32;
ntdate |= delivery_date->dwLowDateTime;
item->header.recieved_time = nt_time_to_unix(ntdate);
item->header.recieved_time = exchange_mapi_util_filetime_to_time_t (delivery_date);
}
if (flags && (*flags & MSGFLAG_READ) != 0)
......
......@@ -1136,3 +1136,37 @@ exchange_mapi_util_free_binary_r (struct Binary_r *bin)
g_free (bin->lpb);
g_free (bin);
}
time_t
exchange_mapi_util_filetime_to_time_t (const struct FILETIME *filetime)
{
NTTIME nt;
if (!filetime)
return (time_t) -1;
nt = filetime->dwHighDateTime;
nt = nt << 32;
nt |= filetime->dwLowDateTime;
nt /= 10 * 1000 * 1000;
nt -= 11644473600LL;
return (time_t) nt;
}
void
exchange_mapi_util_time_t_to_filetime (const time_t tt, struct FILETIME *filetime)
{
NTTIME nt;
g_return_if_fail (filetime != NULL);
nt = tt;
nt += 11644473600LL;
nt *= 10 * 1000 * 1000;
filetime->dwLowDateTime = nt & 0xFFFFFFFF;
nt = nt >> 32;
filetime->dwHighDateTime = nt & 0xFFFFFFFF;
}
......@@ -83,4 +83,7 @@ uint32_t exchange_mapi_utils_push_crc32 (uint32_t crc32, uint8_t *bytes, uint32_
struct Binary_r *exchange_mapi_util_copy_binary_r (const struct Binary_r *bin);
void exchange_mapi_util_free_binary_r (struct Binary_r *bin);
time_t exchange_mapi_util_filetime_to_time_t (const struct FILETIME *filetime);
void exchange_mapi_util_time_t_to_filetime (const time_t tt, struct FILETIME *filetime);
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment