- char *p = t;
- int mode = 1;
-
- while (p && *p) {
- if (mode == 1 && *p == '<') {
- *name = substr(t, p - 1);
- t = p;
- mode++;
- } else if (mode == 1 && *p == '\n') {
- *name = substr(t, p);
- p++;
- break;
- } else if (mode == 2 && *p == '>') {
- *email = substr(t, p + 1);
- t = p;
- mode++;
- } else if (mode == 2 && *p == '\n') {
- *email = substr(t, p);
- p++;
- break;
- } else if (mode == 3 && isdigit(*p)) {
- *date = atol(p);
- mode++;
- } else if (*p == '\n') {
- p++;
- break;
- }
- p++;
+ struct ident_split ident;
+ unsigned email_len;
+
+ if (!split_ident_line(&ident, t, strchrnul(t, '\n') - t)) {
+ *name = substr(ident.name_begin, ident.name_end);
+
+ email_len = ident.mail_end - ident.mail_begin;
+ *email = xmalloc(strlen("<") + email_len + strlen(">") + 1);
+ xsnprintf(*email, email_len + 3, "<%.*s>", email_len, ident.mail_begin);
+
+ if (ident.date_begin)
+ *date = strtoul(ident.date_begin, NULL, 10);
+ if (ident.tz_begin)
+ *tz = atoi(ident.tz_begin);