var rfc2822 = [
  "From",
  "Sender",
  "Reply-To",
  "To",
  "Cc",
  "Bcc",
  "Message-ID",
  "In-Reply-To",
  "References",
  "Resent-From",
  "Resent-Sender",
  "Resent-To",
  "Resent-Cc",
  "Resent-Bcc",
  "Resent-Message-ID",
  "Return-Path",
  "Received"
], rfc2822NoEmail = [
  "Date",
  "Subject",
  "Comments",
  "Keywords",
  "Resent-Date"
], whitespace = /^[ \t]/, separator = /^From /, rfc2822Header = /* @__PURE__ */ RegExp("^(" + rfc2822.join("|") + "): "), rfc2822HeaderNoEmail = /* @__PURE__ */ RegExp("^(" + rfc2822NoEmail.join("|") + "): "), header = /^[^:]+:/, email = /^[^ ]+@[^ ]+/, untilEmail = /^.*?(?=[^ ]+?@[^ ]+)/, bracketedEmail = /^<.*?>/, untilBracketedEmail = /^.*?(?=<.*>)/;
function styleForHeader(e) {
  return e === "Subject" ? "header" : "string";
}
function readToken(e, d) {
  if (e.sol()) {
    if (d.inSeparator = false, d.inHeader && e.match(whitespace)) return null;
    if (d.inHeader = false, d.header = null, e.match(separator)) return d.inHeaders = true, d.inSeparator = true, "atom";
    var f, p = false;
    return (f = e.match(rfc2822HeaderNoEmail)) || (p = true) && (f = e.match(rfc2822Header)) ? (d.inHeaders = true, d.inHeader = true, d.emailPermitted = p, d.header = f[1], "atom") : d.inHeaders && (f = e.match(header)) ? (d.inHeader = true, d.emailPermitted = true, d.header = f[1], "atom") : (d.inHeaders = false, e.skipToEnd(), null);
  }
  if (d.inSeparator) return e.match(email) ? "link" : (e.match(untilEmail) || e.skipToEnd(), "atom");
  if (d.inHeader) {
    var m = styleForHeader(d.header);
    if (d.emailPermitted) {
      if (e.match(bracketedEmail)) return m + " link";
      if (e.match(untilBracketedEmail)) return m;
    }
    return e.skipToEnd(), m;
  }
  return e.skipToEnd(), null;
}
const mbox = {
  name: "mbox",
  startState: function() {
    return {
      inSeparator: false,
      inHeader: false,
      emailPermitted: false,
      header: null,
      inHeaders: false
    };
  },
  token: readToken,
  blankLine: function(e) {
    e.inHeaders = e.inSeparator = e.inHeader = false;
  },
  languageData: { autocomplete: rfc2822.concat(rfc2822NoEmail) }
};
export {
  mbox as t
};
