return GPOINTER_TO_INT(a) - GPOINTER_TO_INT(b);
}
-gchar *generate_msgid(gchar *buf, gint len, gchar *user_addr)
-{
- struct tm *lt;
- time_t t;
- gchar *addr;
- struct tm buft;
-
- t = time(NULL);
- lt = localtime_r(&t, &buft);
-
- if (user_addr != NULL)
- addr = g_strdup_printf(".%s", user_addr);
- else if (strlen(buf) != 0)
- addr = g_strdup_printf("@%s", buf);
- else
- addr = g_strdup_printf("@%s", get_domain_name());
-
- /* Replace all @ but the last one in addr, with underscores.
- * RFC 2822 States that msg-id syntax only allows one @.
- */
- while (strchr(addr, '@') != NULL && strchr(addr, '@') != strrchr(addr, '@'))
- *(strchr(addr, '@')) = '_';
-
- g_snprintf(buf, len, "%04d%02d%02d%02d%02d%02d.%08x%s",
- lt->tm_year + 1900, lt->tm_mon + 1,
- lt->tm_mday, lt->tm_hour,
- lt->tm_min, lt->tm_sec,
- (guint) rand(), addr);
-
- g_free(addr);
- return buf;
-}
-
/*
quote_cmd_argument()
gint g_int_compare (gconstpointer a, gconstpointer b);
-gchar *generate_msgid (gchar *buf, gint len, gchar *user_addr);
gchar *generate_mime_boundary (const gchar *prefix);
gint quote_cmd_argument(gchar * result, guint size,
}
/* Resent-Message-ID */
- if (compose->account->set_domain && compose->account->domain) {
- g_snprintf(buf, sizeof(buf), "%s", compose->account->domain);
- } else if (!strncmp(get_domain_name(), "localhost", strlen("localhost"))) {
- g_snprintf(buf, sizeof(buf), "%s",
- strchr(compose->account->address, '@') ?
- strchr(compose->account->address, '@')+1 :
- compose->account->address);
- } else {
- g_snprintf(buf, sizeof(buf), "%s", "");
- }
-
if (compose->account->gen_msgid) {
- gchar *addr = NULL;
- if (compose->account->msgid_with_addr) {
- addr = compose->account->address;
- }
- generate_msgid(buf, sizeof(buf), addr);
- err |= (fprintf(fp, "Resent-Message-ID: <%s>\n", buf) < 0);
+ gchar *addr = prefs_account_generate_msgid(compose->account);
+ err |= (fprintf(fp, "Resent-Message-ID: <%s>\n", addr) < 0);
if (compose->msgid)
g_free(compose->msgid);
- compose->msgid = g_strdup(buf);
+ compose->msgid = addr;
} else {
compose->msgid = NULL;
}
g_free(str);
/* Message-ID */
- if (compose->account->set_domain && compose->account->domain) {
- g_snprintf(buf, sizeof(buf), "%s", compose->account->domain);
- } else if (!strncmp(get_domain_name(), "localhost", strlen("localhost"))) {
- g_snprintf(buf, sizeof(buf), "%s",
- strchr(compose->account->address, '@') ?
- strchr(compose->account->address, '@')+1 :
- compose->account->address);
- } else {
- g_snprintf(buf, sizeof(buf), "%s", "");
- }
-
if (compose->account->gen_msgid) {
- gchar *addr = NULL;
- if (compose->account->msgid_with_addr) {
- addr = compose->account->address;
- }
- generate_msgid(buf, sizeof(buf), addr);
- g_string_append_printf(header, "Message-ID: <%s>\n", buf);
+ gchar *addr = prefs_account_generate_msgid(compose->account);
+ g_string_append_printf(header, "Message-ID: <%s>\n", addr);
if (compose->msgid)
g_free(compose->msgid);
- compose->msgid = g_strdup(buf);
+ compose->msgid = addr;
} else {
compose->msgid = NULL;
}
goto FILE_ERROR;
/* Message ID */
- if (account->set_domain && account->domain) {
- g_snprintf(buf, sizeof(buf), "%s", account->domain);
- } else if (!strncmp(get_domain_name(), "localhost", strlen("localhost"))) {
- g_snprintf(buf, sizeof(buf), "%s",
- strchr(account->address, '@') ?
- strchr(account->address, '@')+1 :
- account->address);
- } else {
- g_snprintf(buf, sizeof(buf), "%s", "");
- }
-
if (account->gen_msgid) {
- gchar *addr = NULL;
- if (account->msgid_with_addr) {
- addr = account->address;
- }
- generate_msgid(buf, sizeof(buf), addr);
-
- if (fprintf(fp, "Message-ID: <%s>\n", buf) < 0)
+ gchar *addr = prefs_account_generate_msgid(account);
+ if (fprintf(fp, "Message-ID: <%s>\n", addr) < 0) {
+ g_free(addr);
goto FILE_ERROR;
+ }
+ g_free(addr);
}
boundary = generate_mime_boundary("DN");
enum icalparameter_partstat status;
gchar *prefix = NULL;
gchar enc_subject[512], enc_from[512], *from = NULL;
- gchar msgid[128];
+ gchar *msgid;
gchar *calmsgid = NULL;
cm_return_val_if_fail(account != NULL, NULL);
calmsgid = g_strdup("");
}
- if (account && account->set_domain && account->domain) {
- g_snprintf(msgid, sizeof(msgid), "%s", account->domain);
- } else if (!strncmp(get_domain_name(), "localhost", strlen("localhost"))) {
- g_snprintf(msgid, sizeof(msgid), "%s",
- strchr(account->address, '@') ?
- strchr(account->address, '@')+1 :
- account->address);
- } else {
- g_snprintf(msgid, sizeof(msgid), "%s", "");
- }
-
- generate_msgid(msgid, sizeof(msgid), account->address);
+ msgid = prefs_account_generate_msgid(account);
result = g_strdup_printf("%s"
"From: %s <%s>\n"
g_free(save_folder);
g_free(queue_headers);
g_free(attendees);
+ g_free(msgid);
return result;
organizer_name = get_organizer_name(meet);
- if (account->set_domain && account->domain) {
- g_snprintf(buf, sizeof(buf), "%s", account->domain);
- } else if (!strncmp(get_domain_name(), "localhost", strlen("localhost"))) {
- g_snprintf(buf, sizeof(buf), "%s",
- strchr(account->address, '@') ?
- strchr(account->address, '@')+1 :
- account->address);
- } else {
- g_snprintf(buf, sizeof(buf), "%s", "");
- }
- generate_msgid(buf, 255, account->address);
-
if (meet->uid) {
uid = g_strdup(meet->uid);
} else {
- uid = g_strdup(buf);
+ uid = prefs_account_generate_msgid(account);
}
dtstart = get_date(meet, TRUE);
}
if (fp) {
- gchar uid[256];
+ gchar *uid;
time_t t = time(NULL);
time_t t2 = t+3600;
gchar *org = NULL;
org = g_strdup(account->address);
- if (account->set_domain && account->domain) {
- g_snprintf(uid, sizeof(uid), "%s", account->domain);
- } else if (!strncmp(get_domain_name(), "localhost", strlen("localhost"))) {
- g_snprintf(uid, sizeof(uid), "%s",
- strchr(account->address, '@') ?
- strchr(account->address, '@')+1 :
- account->address);
- } else {
- g_snprintf(uid, sizeof(uid), "%s", "");
- }
- generate_msgid(uid, 255, account->address);
+ uid = prefs_account_generate_msgid(account);
event = vcal_manager_new_event(uid,
org, NULL, NULL/*location*/, summary, description,
dtstart, dtend, recur, tzid, url, method, sequence,
ICAL_VTODO_COMPONENT);
+ g_free(uid);
/* hack to get default hours */
g_free(event->dtstart);
}
#endif
+gchar *prefs_account_generate_msgid(PrefsAccount *account)
+{
+ gchar *addr, *tmbuf, *buf = NULL;
+ GDateTime *now;
+ gchar *user_addr = account->msgid_with_addr ? account->address : NULL;
+
+ if (account->set_domain && account->domain) {
+ buf = g_strdup(account->domain);
+ } else if (!strncmp(get_domain_name(), "localhost", strlen("localhost"))) {
+ buf = g_strdup(
+ strchr(account->address, '@') ?
+ strchr(account->address, '@')+1 :
+ account->address);
+ }
+
+ if (user_addr != NULL) {
+ addr = g_strdup_printf(".%s", user_addr);
+ } else {
+ addr = g_strdup_printf("@%s",
+ buf != NULL && strlen(buf) > 0 ?
+ buf : get_domain_name());
+ }
+
+ if (buf != NULL)
+ g_free(buf);
+ if (user_addr != NULL)
+ g_free(user_addr);
+
+ /* Replace all @ but the last one in addr, with underscores.
+ * RFC 2822 States that msg-id syntax only allows one @.
+ */
+ while (strchr(addr, '@') != NULL && strchr(addr, '@') != strrchr(addr, '@'))
+ *(strchr(addr, '@')) = '_';
+
+ now = g_date_time_new_now_local();
+ tmbuf = g_date_time_format(now, "%Y%m%d%H%M%S");
+ buf = g_strdup_printf("%s.%08x%s",
+ tmbuf, (guint)rand(), addr);
+ g_free(tmbuf);
+ g_free(addr);
+
+ debug_print("Generated Message-ID string '%s'\n", buf);
+ return buf;
+}
+
void prefs_account_register_page(PrefsPage *page)
{
prefs_pages = g_slist_append(prefs_pages, page);
const gchar *prefs_account_get_privacy_prefs(PrefsAccount *account, gchar *id);
void prefs_account_set_privacy_prefs(PrefsAccount *account, gchar *id, gchar *new_value);
+gchar *prefs_account_generate_msgid(PrefsAccount *account);
void prefs_account_register_page (PrefsPage *page);
void prefs_account_unregister_page (PrefsPage *page);