static void accum_time_attribute (GString *buffer, EContact *contact, const gchar *html_label, EContactField field, const gchar *icon, guint html_flags) { EContactDate *date; GDate *gdate = NULL; gchar sdate[100]; date = e_contact_get (contact, field); if (date) { gdate = g_date_new_dmy ( date->day, date->month, date->year); g_date_strftime (sdate, 100, "%x", gdate); g_date_free (gdate); render_table_row (buffer, html_label, sdate, icon, html_flags); e_contact_date_free (date); } }
static gboolean parseLine (CSVImporter *gci, EContact *contact, gchar *buf) { const gchar *pptr = buf, *field_text; gchar *do_free = NULL; GString *value; gint ii = 0, idx; gint flags = 0; gint contact_field; EContactAddress *home_address = NULL, *work_address = NULL, *other_address = NULL; EContactDate *bday = NULL; GString *home_street, *work_street, *other_street; home_street = g_string_new (""); work_street = g_string_new (""); other_street = g_string_new (""); home_address = e_contact_address_new (); work_address = e_contact_address_new (); other_address = e_contact_address_new (); bday = e_contact_date_new (); if (!g_utf8_validate (pptr, -1, NULL)) { do_free = g_convert (pptr, -1, "UTF-8", "ISO-8859-1", NULL, NULL, NULL); pptr = do_free; } while (value = parseNextValue (&pptr), value != NULL) { contact_field = NOMAP; flags = FLAG_INVALID; field_text = NULL; idx = ii; if (gci->fields_map) { gpointer found; found = g_hash_table_lookup ( gci->fields_map, GINT_TO_POINTER (idx)); if (found == NULL) { g_warning ("%s: No map for index %d, skipping it", G_STRFUNC, idx); idx = -1; } else { idx = GPOINTER_TO_INT (found) - 1; } } if (importer == OUTLOOK_IMPORTER) { if (idx >= 0 && idx < G_N_ELEMENTS (csv_fields_outlook)) { contact_field = csv_fields_outlook[idx].contact_field; flags = csv_fields_outlook[idx].flags; field_text = csv_fields_outlook[idx].csv_attribute; } } else if (importer == MOZILLA_IMPORTER) { if (idx >= 0 && idx < G_N_ELEMENTS (csv_fields_mozilla)) { contact_field = csv_fields_mozilla[idx].contact_field; flags = csv_fields_mozilla[idx].flags; field_text = csv_fields_mozilla[idx].csv_attribute; } } else { if (idx >= 0 && idx < G_N_ELEMENTS (csv_fields_evolution)) { contact_field = csv_fields_evolution[idx].contact_field; flags = csv_fields_evolution[idx].flags; field_text = csv_fields_evolution[idx].csv_attribute; } } if (*value->str) { if (contact_field != NOMAP) { if (importer == OUTLOOK_IMPORTER || importer == MOZILLA_IMPORTER) { e_contact_set (contact, contact_field, value->str); } else { if (contact_field == E_CONTACT_WANTS_HTML) e_contact_set ( contact, contact_field, GINT_TO_POINTER ( g_ascii_strcasecmp ( value->str, "TRUE") == 0)); else e_contact_set (contact, contact_field, value->str); } } else { switch (flags) { case FLAG_HOME_ADDRESS | FLAG_STREET: if (strlen (home_street->str) != 0) { home_street = g_string_append (home_street, ",\n"); } home_street = g_string_append (home_street, value->str); break; case FLAG_HOME_ADDRESS | FLAG_CITY: home_address->locality = g_strdup (value->str); break; case FLAG_HOME_ADDRESS | FLAG_STATE: home_address->region = g_strdup (value->str); break; case FLAG_HOME_ADDRESS | FLAG_POSTAL_CODE: home_address->code = g_strdup (value->str); break; case FLAG_HOME_ADDRESS | FLAG_POBOX: home_address->po = g_strdup (value->str); break; case FLAG_HOME_ADDRESS | FLAG_COUNTRY: home_address->country = g_strdup (value->str); break; case FLAG_WORK_ADDRESS | FLAG_STREET: if (strlen (work_street->str) != 0) { work_street = g_string_append (work_street, ",\n"); } work_street = g_string_append (work_street, value->str); break; case FLAG_WORK_ADDRESS | FLAG_CITY: work_address->locality = g_strdup (value->str); break; case FLAG_WORK_ADDRESS | FLAG_STATE: work_address->region = g_strdup (value->str); break; case FLAG_WORK_ADDRESS | FLAG_POSTAL_CODE: work_address->code = g_strdup (value->str); break; case FLAG_WORK_ADDRESS | FLAG_POBOX: work_address->po = g_strdup (value->str); break; case FLAG_WORK_ADDRESS | FLAG_COUNTRY: work_address->country = g_strdup (value->str); break; case FLAG_OTHER_ADDRESS | FLAG_STREET: if (strlen (other_street->str) != 0) { other_street = g_string_append (other_street, ",\n"); } other_street = g_string_append (other_street, value->str); break; case FLAG_OTHER_ADDRESS | FLAG_CITY: other_address->locality = g_strdup (value->str); break; case FLAG_OTHER_ADDRESS | FLAG_STATE: other_address->region = g_strdup (value->str); break; case FLAG_OTHER_ADDRESS | FLAG_POSTAL_CODE: other_address->code = g_strdup (value->str); break; case FLAG_OTHER_ADDRESS | FLAG_POBOX: other_address->po = g_strdup (value->str); break; case FLAG_OTHER_ADDRESS | FLAG_COUNTRY: other_address->country = g_strdup (value->str); break; case FLAG_DATE_BDAY: e_contact_set ( contact, E_CONTACT_BIRTH_DATE, date_from_string (value->str)); break; case FLAG_DATE_ANNIVERSARY: e_contact_set ( contact, E_CONTACT_ANNIVERSARY, date_from_string (value->str)); break; case FLAG_BIRTH_DAY: bday->day = atoi (value->str); break; case FLAG_BIRTH_YEAR: bday->year = atoi (value->str); break; case FLAG_BIRTH_MONTH: bday->month = atoi (value->str); break; case FLAG_INVALID: break; default: add_to_notes (contact, field_text, value->str); } } } ii++; g_string_free (value, TRUE); } if (strlen (home_street->str) != 0) home_address->street = g_strdup (home_street->str); if (strlen (work_street->str) != 0) work_address->street = g_strdup (work_street->str); if (strlen (other_street->str) != 0) other_address->street = g_strdup (other_street->str); g_string_free (home_street, TRUE); g_string_free (work_street, TRUE); g_string_free (other_street, TRUE); if (home_address->locality || home_address->country || home_address->code || home_address->region || home_address->street) e_contact_set (contact, E_CONTACT_ADDRESS_HOME, home_address); if (work_address->locality || work_address->country || work_address->code || work_address->region || work_address->street) e_contact_set (contact, E_CONTACT_ADDRESS_WORK, work_address); if (other_address->locality || other_address->country || other_address->code || other_address->region || other_address->street) e_contact_set (contact, E_CONTACT_ADDRESS_OTHER, other_address); if (importer != OUTLOOK_IMPORTER) { if (bday->day || bday->year || bday->month) e_contact_set (contact, E_CONTACT_BIRTH_DATE, bday); } e_contact_address_free (home_address); e_contact_address_free (work_address); e_contact_address_free (other_address); e_contact_date_free (bday); g_free (do_free); return TRUE; }
static ESExpResult * entry_compare (SearchContext *ctx, struct _ESExp *f, gint argc, struct _ESExpResult **argv, CompareFunc compare) { ESExpResult *r; gint truth = FALSE; if ((argc == 2 && argv[0]->type == ESEXP_RES_STRING && argv[1]->type == ESEXP_RES_STRING) || (argc == 3 && argv[0]->type == ESEXP_RES_STRING && argv[1]->type == ESEXP_RES_STRING && argv[2]->type == ESEXP_RES_STRING)) { gchar *propname; struct prop_info *info = NULL; const gchar *region = NULL; gint i; gboolean any_field; gboolean saw_any = FALSE; if (argc > 2) region = argv[2]->value.string; propname = argv[0]->value.string; any_field = !strcmp (propname, "x-evolution-any-field"); for (i = 0; i < G_N_ELEMENTS (prop_info_table); i++) { if (any_field || !strcmp (prop_info_table[i].query_prop, propname)) { saw_any = TRUE; info = &prop_info_table[i]; if (any_field && info->field_id == E_CONTACT_UID) { /* We need to skip UID from any field contains search * any-field search should be supported for the * visible fields only. */ truth = FALSE; } else if (info->prop_type == PROP_TYPE_NORMAL) { const gchar *prop = NULL; /* straight string property matches */ prop = e_contact_get_const (ctx->contact, info->field_id); if (prop && compare (prop, argv[1]->value.string, region)) { truth = TRUE; } if ((!prop) && compare ("", argv[1]->value.string, region)) { truth = TRUE; } } else if (info->prop_type == PROP_TYPE_LIST) { /* the special searches that match any of the list elements */ truth = info->list_compare (ctx->contact, argv[1]->value.string, region, compare); } else if (info->prop_type == PROP_TYPE_DATE) { /* the special searches that match dates */ EContactDate *date; date = e_contact_get (ctx->contact, info->field_id); if (date) { truth = compare_date (date, argv[1]->value.string, region, compare); e_contact_date_free (date); } } else { g_warn_if_reached (); saw_any = FALSE; break; } /* if we're looking at all fields and find a match, * or if we're just looking at this one field, * break. */ if ((any_field && truth) || !any_field) break; } } if (!saw_any) { /* propname didn't match to any of our known "special" properties, * so try to find if it isn't a real field and if so, then compare * against value in this field only */ EContactField fid = e_contact_field_id (propname); if (fid >= E_CONTACT_FIELD_FIRST && fid < E_CONTACT_FIELD_LAST) { const gchar *prop = e_contact_get_const (ctx->contact, fid); if (prop && compare (prop, argv[1]->value.string, region)) { truth = TRUE; } if ((!prop) && compare ("", argv[1]->value.string, region)) { truth = TRUE; } } else { /* it is not direct EContact known field, so try to find * it in EVCard attributes */ GList *a, *attrs = e_vcard_get_attributes (E_VCARD (ctx->contact)); for (a = attrs; a && !truth; a = a->next) { EVCardAttribute *attr = (EVCardAttribute *) a->data; if (g_ascii_strcasecmp (e_vcard_attribute_get_name (attr), propname) == 0) { GList *l, *values = e_vcard_attribute_get_values (attr); for (l = values; l && !truth; l = l->next) { const gchar *value = l->data; if (value && compare (value, argv[1]->value.string, region)) { truth = TRUE; } else if ((!value) && compare ("", argv[1]->value.string, region)) { truth = TRUE; } } } } } } } r = e_sexp_result_new (f, ESEXP_RES_BOOL); r->value.boolean = truth; return r; }
static ESExpResult * func_exists (struct _ESExp *f, gint argc, struct _ESExpResult **argv, gpointer data) { SearchContext *ctx = data; ESExpResult *r; gint truth = FALSE; if (argc == 1 && argv[0]->type == ESEXP_RES_STRING) { const gchar *propname; struct prop_info *info = NULL; gint i; gboolean saw_any = FALSE; propname = argv[0]->value.string; for (i = 0; i < G_N_ELEMENTS (prop_info_table); i++) { if (!strcmp (prop_info_table[i].query_prop, propname)) { saw_any = TRUE; info = &prop_info_table[i]; if (info->prop_type == PROP_TYPE_NORMAL) { const gchar *prop = NULL; /* searches where the query's property * maps directly to an ecard property */ prop = e_contact_get_const (ctx->contact, info->field_id); if (prop && *prop) truth = TRUE; } else if (info->prop_type == PROP_TYPE_LIST) { /* the special searches that match any of the list elements */ truth = info->list_compare (ctx->contact, "", NULL, exists_helper); } else if (info->prop_type == PROP_TYPE_DATE) { EContactDate *date; date = e_contact_get (ctx->contact, info->field_id); if (date) { truth = TRUE; e_contact_date_free (date); } } else { g_warn_if_reached (); saw_any = FALSE; } break; } } if (!saw_any) { /* propname didn't match to any of our known "special" properties, * so try to find if it isn't a real field and if so, then check * against value in this field only */ EContactField fid = e_contact_field_id (propname); if (fid >= E_CONTACT_FIELD_FIRST && fid < E_CONTACT_FIELD_LAST && e_contact_field_is_string (fid)) { const gchar *prop = e_contact_get_const (ctx->contact, fid); if (prop && *prop) truth = TRUE; } else { /* is is not a known EContact field, try with EVCard attributes */ EVCardAttribute *attr; GList *l, *values; if (fid >= E_CONTACT_FIELD_FIRST && fid < E_CONTACT_FIELD_LAST) propname = e_contact_vcard_attribute (fid); attr = e_vcard_get_attribute (E_VCARD (ctx->contact), propname); values = attr ? e_vcard_attribute_get_values (attr) : NULL; for (l = values; l && !truth; l = l->next) { const gchar *value = l->data; if (value && *value) truth = TRUE; } } } } r = e_sexp_result_new (f, ESEXP_RES_BOOL); r->value.boolean = truth; return r; }
/* utility functions shared between all contact importers */ static void preview_contact (EWebViewPreview *preview, EContact *contact) { gint idx; gboolean had_value = FALSE; const gint fields[] = { E_CONTACT_FILE_AS, E_CONTACT_CATEGORIES, E_CONTACT_IS_LIST, E_CONTACT_LIST_SHOW_ADDRESSES, E_CONTACT_WANTS_HTML, E_CONTACT_FULL_NAME, E_CONTACT_GIVEN_NAME, E_CONTACT_FAMILY_NAME, E_CONTACT_NICKNAME, E_CONTACT_SPOUSE, E_CONTACT_BIRTH_DATE, E_CONTACT_ANNIVERSARY, E_CONTACT_MAILER, E_CONTACT_EMAIL, -1, E_CONTACT_ORG, E_CONTACT_ORG_UNIT, E_CONTACT_OFFICE, E_CONTACT_TITLE, E_CONTACT_ROLE, E_CONTACT_MANAGER, E_CONTACT_ASSISTANT, -1, E_CONTACT_PHONE_ASSISTANT, E_CONTACT_PHONE_BUSINESS, E_CONTACT_PHONE_BUSINESS_2, E_CONTACT_PHONE_BUSINESS_FAX, E_CONTACT_PHONE_CALLBACK, E_CONTACT_PHONE_CAR, E_CONTACT_PHONE_COMPANY, E_CONTACT_PHONE_HOME, E_CONTACT_PHONE_HOME_2, E_CONTACT_PHONE_HOME_FAX, E_CONTACT_PHONE_ISDN, E_CONTACT_PHONE_MOBILE, E_CONTACT_PHONE_OTHER, E_CONTACT_PHONE_OTHER_FAX, E_CONTACT_PHONE_PAGER, E_CONTACT_PHONE_PRIMARY, E_CONTACT_PHONE_RADIO, E_CONTACT_PHONE_TELEX, E_CONTACT_PHONE_TTYTDD, -1, E_CONTACT_ADDRESS_HOME, E_CONTACT_ADDRESS_WORK, E_CONTACT_ADDRESS_OTHER, -1, E_CONTACT_HOMEPAGE_URL, E_CONTACT_BLOG_URL, E_CONTACT_CALENDAR_URI, E_CONTACT_FREEBUSY_URL, E_CONTACT_ICS_CALENDAR, E_CONTACT_VIDEO_URL, -1, E_CONTACT_IM_AIM, E_CONTACT_IM_GROUPWISE, E_CONTACT_IM_JABBER, E_CONTACT_IM_YAHOO, E_CONTACT_IM_MSN, E_CONTACT_IM_ICQ, E_CONTACT_IM_GADUGADU, E_CONTACT_IM_SKYPE, -1, E_CONTACT_NOTE }; g_return_if_fail (preview != NULL); g_return_if_fail (contact != NULL); for (idx = 0; idx < G_N_ELEMENTS (fields); idx++) { EContactField field; if (fields[idx] == -1) { if (had_value) e_web_view_preview_add_empty_line (preview); had_value = FALSE; continue; } field = fields[idx]; if (field == E_CONTACT_BIRTH_DATE || field == E_CONTACT_ANNIVERSARY) { EContactDate *dt = e_contact_get (contact, field); if (dt) { GDate gd = { 0 }; struct tm tm; gchar *value; g_date_set_dmy (&gd, dt->day, dt->month, dt->year); g_date_to_struct_tm (&gd, &tm); value = e_datetime_format_format_tm ( "addressbook", "table", DTFormatKindDate, &tm); if (value) { e_web_view_preview_add_section ( preview, e_contact_pretty_name (field), value); had_value = TRUE; } g_free (value); e_contact_date_free (dt); } } else if (field == E_CONTACT_IS_LIST || field == E_CONTACT_WANTS_HTML || field == E_CONTACT_LIST_SHOW_ADDRESSES) { if (e_contact_get (contact, field)) { e_web_view_preview_add_text ( preview, e_contact_pretty_name (field)); had_value = TRUE; } } else if (field == E_CONTACT_ADDRESS_HOME || field == E_CONTACT_ADDRESS_WORK || field == E_CONTACT_ADDRESS_OTHER) { EContactAddress *addr = e_contact_get (contact, field); if (addr) { gboolean have = FALSE; #define add_it(_what) \ if (addr->_what && *addr->_what) { \ e_web_view_preview_add_section ( \ preview, have ? NULL : \ e_contact_pretty_name (field), addr->_what); \ have = TRUE; \ had_value = TRUE; \ } add_it (po); add_it (ext); add_it (street); add_it (locality); add_it (region); add_it (code); add_it (country); #undef add_it e_contact_address_free (addr); } } else if (field == E_CONTACT_IM_AIM || field == E_CONTACT_IM_GROUPWISE || field == E_CONTACT_IM_JABBER || field == E_CONTACT_IM_YAHOO || field == E_CONTACT_IM_MSN || field == E_CONTACT_IM_ICQ || field == E_CONTACT_IM_GADUGADU || field == E_CONTACT_IM_SKYPE || field == E_CONTACT_EMAIL) { GList *attrs, *a; gboolean have = FALSE; const gchar *pretty_name; pretty_name = e_contact_pretty_name (field); attrs = e_contact_get_attributes (contact, field); for (a = attrs; a; a = a->next) { EVCardAttribute *attr = a->data; GList *value; if (!attr) continue; value = e_vcard_attribute_get_values (attr); while (value != NULL) { const gchar *str = value->data; if (str && *str) { e_web_view_preview_add_section ( preview, have ? NULL : pretty_name, str); have = TRUE; had_value = TRUE; } value = value->next; } e_vcard_attribute_free (attr); } g_list_free (attrs); } else if (field == E_CONTACT_CATEGORIES) { const gchar *pretty_name; const gchar *value; pretty_name = e_contact_pretty_name (field); value = e_contact_get_const (contact, field); if (value != NULL && *value != '\0') { e_web_view_preview_add_section ( preview, pretty_name, value); had_value = TRUE; } } else { const gchar *pretty_name; const gchar *value; pretty_name = e_contact_pretty_name (field); value = e_contact_get_const (contact, field); if (value != NULL && *value != '\0') { e_web_view_preview_add_section ( preview, pretty_name, value); had_value = TRUE; } } } }