String[] emails = matchMultipleValuePrefix("MAIL", 3, rawText, true);
String note = matchSinglePrefixedField("MEMORY:", rawText, '\r', false);
String address = matchSinglePrefixedField("ADD:", rawText, '\r', true);
- return new AddressBookParsedResult(names, phoneNumbers, emails, note, address, null, null, null);
+ return new AddressBookParsedResult(names, phoneNumbers, emails, note, address, null, null, null, null);
}
private static String[] matchMultipleValuePrefix(String prefix, int max, String rawText, boolean trim) {
/**
* Implements the "MECARD" address book entry format.
*
- * Supported keys: N, TEL, EMAIL, NOTE, ADR Unsupported keys: SOUND, TEL-AV, BDAY, URL, NICKNAME
+ * Supported keys: N, TEL, EMAIL, NOTE, ADR, BDAY, URL, plus ORG
+ * Unsupported keys: SOUND, TEL-AV, NICKNAME
*
* Except for TEL, multiple values for keys are also not supported;
* the first one found takes precedence.
*
+ * Our understanding of the MECARD format is based on this document:
+ *
+ * http://www.mobicode.org.tw/files/OMIA%20Mobile%20Bar%20Code%20Standard%20v3.2.1.doc
+ *
* @author srowen@google.com (Sean Owen)
*/
final class AddressBookDoCoMoResultParser extends AbstractDoCoMoResultParser {
String address = matchSingleDoCoMoPrefixedField("ADR:", rawText, true);
String birthday = matchSingleDoCoMoPrefixedField("BDAY:", rawText, true);
if (birthday != null && !isStringOfDigits(birthday, 8)) {
- return null;
+ // No reason to throw out the whole card because the birthday is formatted wrong.
+ birthday = null;
}
+ String url = matchSingleDoCoMoPrefixedField("URL:", rawText, true);
+
+ // Although ORG may not be strictly legal in MECARD, it does exist in VCARD and we might as well
+ // honor it when found in the wild.
+ String org = matchSingleDoCoMoPrefixedField("ORG:", rawText, true);
+
return new AddressBookParsedResult(maybeWrap(name),
phoneNumbers,
maybeWrap(email),
note,
address,
- null,
+ org,
birthday,
- null);
+ null,
+ url);
}
private static String parseName(String name) {
private final String org;
private final String birthday;
private final String title;
+ private final String url;
public AddressBookParsedResult(String[] names,
String[] phoneNumbers,
String address,
String org,
String birthday,
- String title) {
+ String title,
+ String url) {
super(ParsedResultType.ADDRESSBOOK);
this.names = names;
this.phoneNumbers = phoneNumbers;
this.org = org;
this.birthday = birthday;
this.title = title;
+ this.url = url;
}
public String[] getNames() {
return org;
}
+ public String getURL() {
+ return url;
+ }
+
/**
* @return birthday formatted as yyyyMMdd (e.g. 19780917)
*/
maybeAppend(org, result);
maybeAppend(birthday, result);
maybeAppend(title, result);
+ maybeAppend(url, result);
return result.toString();
}
address,
org,
null,
- title);
+ title,
+ null);
}
private static String[] buildPhoneNumbers(String number1, String number2, String number3) {
return null;
}
String title = matchSingleVCardPrefixedField("TITLE", rawText, true);
- return new AddressBookParsedResult(names, phoneNumbers, emails, note, address, org, birthday, title);
+ String url = matchSingleVCardPrefixedField("URL", rawText, true);
+ return new AddressBookParsedResult(names, phoneNumbers, emails, note, address, org, birthday,
+ title, url);
}
private static String[] matchVCardPrefixedField(String prefix, String rawText, boolean trim) {
address,
org,
birthday,
- title);
+ title,
+ null);
}
}
\ No newline at end of file