@SuppressWarnings("unchecked") private void copyEmail(Map<String, Object> map, VCard card) { getListMap("emailAddresses", map) .ifPresent( v -> v.forEach( email -> getString("address", email) .ifPresent(addr -> card.addEmail(new Email(addr))))); }
@SuppressWarnings("unchecked") private void addEmail(Email email, Map<String, Object> map) { List<Map<String, String>> collection = (List<Map<String, String>>) map.computeIfAbsent("emailAddresses", k -> new ArrayList<>()); Map<String, String> emailMap = new LinkedHashMap<>(); emailMap.put("address", email.getValue()); collection.add(emailMap); } }
private static EmailAddress convertToGoogleEmail(Email vCardEmail) { EmailAddress emailAddress = new EmailAddress(); emailAddress.setValue(vCardEmail.getValue()); if (vCardEmail.getPref() != null && vCardEmail.getPref() == VCARD_PRIMARY_PREF) { emailAddress.setMetadata(PRIMARY_FIELD_METADATA); } else { emailAddress.setMetadata(SECONDARY_FIELD_METADATA); } // TODO(olsona): address display name, formatted type, etc return emailAddress; }
String mailTo = "mailto:" + email.getValue(); if (email.getTypes().isEmpty()) { r.addProperty(VCARD4.hasEmail, mailTo); } else { Resource emailResource = personModel.createResource(); emailResource.addProperty(VCARD4.value, mailTo); for (EmailType type : email.getTypes()) { for (Resource emailTypeResource : getPhoneOrMailTypes(type.getValue(), MAP_OF_EMAIL_TYPES)) {
checkState(matcher.matches(), "%s mail to address doesn't match", mailTo); String emailAddress = matcher.group(1); Email email = new Email(emailAddress); if (emailResource.hasProperty(RDF.type)) { emailResource.listProperties(RDF.type).forEachRemaining(typeProperty -> email.getTypes().add(EmailType.find(typeProperty.getResource().getLocalName()))); checkState(matcher.matches(), "%s mail to address doesn't match", mailTo); String emailAddress = matcher.group(1); Email email = new Email(emailAddress); vcard.addEmail(email);
@Override protected Email _parseHtml(HCardElement element, ParseContext context) { String href = element.attr("href"); String email = extractEmailFromHrefAttribute(href); if (email == null) { email = element.value(); } Email property = new Email(email); List<String> types = element.types(); property.getParameters().putAll(VCardParameters.TYPE, types); return property; }
@Override protected void _validate(List<ValidationWarning> warnings, VCardVersion version, VCard vcard) { super._validate(warnings, version, vcard); for (EmailType type : getTypes()) { if (type == EmailType.PREF) { //ignore because it is converted to a PREF parameter for 4.0 vCards continue; } if (!type.isSupportedBy(version)) { warnings.add(new ValidationWarning(9, type.getValue())); } } }
/** * <p> * Adds an email address. * </p> * <p> * <b>Property name:</b> {@code EMAIL}<br> * <b>Supported versions:</b> {@code 2.1, 3.0, 4.0} * </p> * @param email the email address to add (e.g. "johndoe@aol.com") * @param types the type(s) to assign to the email * @return the property object that was created * @see <a href="http://tools.ietf.org/html/rfc6350#page-36">RFC 6350 * p.36</a> * @see <a href="http://tools.ietf.org/html/rfc2426#page-15">RFC 2426 * p.15</a> * @see <a href="http://www.imc.org/pdi/vcard-21.doc">vCard 2.1 p.15</a> */ public Email addEmail(String email, EmailType... types) { Email property = new Email(email); property.getTypes().addAll(Arrays.asList(types)); addEmail(property); return property; }
if (nbEmailAddr > 1) { boolean workEmail = false; for (EmailType emailType : email.getTypes()) { if (EmailType.PREF.equals(emailType) || EmailType.WORK.equals(emailType)) { workEmail = true; String emailAddr = email.getValue(); if (UtilValidate.isEmail(emailAddr)) { serviceCtx.put("emailAddress", emailAddr);
@Override public Email copy() { return new Email(this); } }
String secondaryString1 = "secondary1@email.com"; String secondaryString2 = "secondary2@email.com"; Email primaryEmail = new Email(primaryString); primaryEmail.setPref(VCARD_PRIMARY_PREF); Email secondaryEmail1 = new Email(secondaryString1); secondaryEmail1.setPref(VCARD_PRIMARY_PREF + 1); Email secondaryEmail2 = new Email(secondaryString2); secondaryEmail2.setPref(VCARD_PRIMARY_PREF + 1);
private void copyPersonData(VCard card, Map<String, Object> contact, TransformerContext context) { // Addresses are lossy: there is no distinction in VCard between business and home addresses if (!card.getAddresses().isEmpty()) { safeSet( "homeAddress", context.transform(LinkedHashMap.class, card.getAddresses().get(0)), contact); } card.getEmails().stream().filter(v -> v.getValue() != null).forEach(v -> addEmail(v, contact)); card.getTelephoneNumbers() .stream() .filter(t -> t.getText() != null) .forEach( telephone -> { for (TelephoneType telephoneType : telephone.getTypes()) { if (TelephoneType.CELL.equals(telephoneType)) { // this could overwrite some numbers since MS contacts only have one mobile contact.put("mobilePhone", telephone.getText()); } else if (TelephoneType.WORK.equals(telephoneType)) { addPhone("businessPhones", telephone, contact); } else { addPhone("homePhones", telephone, contact); } } }); if (card.getBirthday() != null) { safeSet("birthday", card.getBirthday().getText(), contact); } }
@Override protected Email _parseValue(String value) { return new Email(value); }
@Test public void testFromRDF() { VCard vcard = SolidContactsExport.parsePerson(getPersonResource(TestData.RDF_TEST_DATA1)); assertWithMessage("Formatted Name is correct") .that(vcard.getFormattedName().getValue()) .isEqualTo("Cool Kid 1"); assertWithMessage("Note is correct") .that(vcard.getNotes().get(0).getValue()) .isEqualTo("This is a note for Cool Kid 1"); assertWithMessage("One email found") .that(vcard.getEmails()) .hasSize(1); assertWithMessage("email is correct") .that(vcard.getEmails().get(0).getValue()) .isEqualTo("a@b.com"); }
vcard.addEmail(new Email(emailAddress.getString("infoString")));