More support for pre-Epoch dates for Windows.
[claws.git] / src / plugins / vcalendar / vcal_manager.c
index 58675143dddb7eabfcbcfa2ef29dea894183f6e9..1432e0f36ee6640e5037e4d8f015dcd059f6eccb 100644 (file)
@@ -347,7 +347,7 @@ gchar *vcal_manager_event_dump(VCalEvent *event, gboolean is_reply, gboolean is_
                                 "-//Claws Mail//NONSGML Claws Mail Calendar//EN"),
                            icalproperty_new_calscale("GREGORIAN"),
                            icalproperty_new_method(is_reply ? ICAL_METHOD_REPLY:event->method),
-                           0
+                           (void*)0
                            );  
 
        if (!calendar) {
@@ -380,7 +380,7 @@ gchar *vcal_manager_event_dump(VCalEvent *event, gboolean is_reply, gboolean is_
 
        ievent = 
            icalcomponent_vanew(
-                ICAL_VEVENT_COMPONENT, 0);
+                ICAL_VEVENT_COMPONENT, (void*)0);
 
        if (!ievent) {
                g_warning ("can't generate event");
@@ -519,24 +519,24 @@ gchar *vcal_manager_event_dump(VCalEvent *event, gboolean is_reply, gboolean is_
 
 static void get_rfc822_date_from_time_t(gchar *buf, gint len, time_t t)
 {
+#ifndef G_OS_WIN32
        struct tm *lt;
        gchar day[4], mon[4];
        gint dd, hh, mm, ss, yyyy;
        gchar buft1[512];
        struct tm buft2;
 
-#ifndef G_OS_WIN32
        lt = localtime_r(&t, &buft2);
-#else
-       if (t < 0)
-               t = 1;
-       lt = localtime(&t);
-#endif
-
        sscanf(asctime_r(lt, buft1), "%3s %3s %d %d:%d:%d %d\n",
               day, mon, &dd, &hh, &mm, &ss, &yyyy);
        g_snprintf(buf, len, "%s, %d %s %d %02d:%02d:%02d %s",
                   day, dd, mon, yyyy, hh, mm, ss, tzoffset(&t));
+#else
+       GDateTime *dt = g_date_time_new_from_unix_local(t);
+       gchar *buf2 = g_date_time_format(dt, "%a, %e %b %Y %H:%M:%S %Z");
+       strncpy(buf, buf2, len);
+       g_free(buf2);
+#endif
 }
 
 static gchar *write_headers_date(const gchar *uid)
@@ -700,7 +700,7 @@ gchar *vcal_manager_icalevent_dump(icalcomponent *event, gchar *orga, icalcompon
                                 "-//Claws Mail//NONSGML Claws Mail Calendar//EN"),
                            icalproperty_new_calscale("GREGORIAN"),
                            icalproperty_new_method(ICAL_METHOD_PUBLISH),
-                           0
+                           (void*)0
                            );  
 
        if (!calendar) {
@@ -729,18 +729,19 @@ gchar *vcal_manager_icalevent_dump(icalcomponent *event, gchar *orga, icalcompon
        
        /* encode to quoted-printable */
        while (lines[i]) {
-               gchar buf[256];
                gint e_len = strlen(qpbody), n_len = 0;
                gchar *outline = conv_codeset_strdup(lines[i], CS_UTF_8, conv_get_outgoing_charset_str());
+               gchar *qpoutline = g_malloc(strlen(outline)*8 + 1);
                
-               qp_encode_line(buf, (guchar *)outline);
-               n_len = strlen(buf);
+               qp_encode_line(qpoutline, (guchar *)outline);
+               n_len = strlen(qpoutline);
                
                qpbody = g_realloc(qpbody, e_len + n_len + 1);
-               strcpy(qpbody+e_len, buf);
+               strcpy(qpbody+e_len, qpoutline);
                *(qpbody+n_len+e_len) = '\0';
                
                g_free(outline);
+               g_free(qpoutline);
                i++;
        }
        
@@ -920,7 +921,7 @@ void vcal_manager_save_event (VCalEvent *event, gboolean export_after)
        xml_tag_add_attr(tag, xml_attr_new("type", tmp));
        g_free(tmp);
        
-       tmp = g_strdup_printf("%lu", event->postponed);
+       tmp = g_strdup_printf("%lld", (long long)event->postponed);
        xml_tag_add_attr(tag, xml_attr_new("postponed", tmp));
        g_free(tmp);