Skip to content

armgit / laya

Public Imported from GitHub
0

Non-autoregressive System 1 decision engine. Typed choice, score and yes/no decisions over any text in a single forward pass, in 100+ languages, with a router that picks the right checkpoint per request.

fix(email): preserve requests and trim extended device footers

Lloyd Aloysius0e4f37c54d68
diff --git a/laya-ts/src/email.ts b/laya-ts/src/email.ts
index 09c1cc24..16debb58 100644
--- a/laya-ts/src/email.ts
+++ b/laya-ts/src/email.ts
@@ -30,18 +30,18 @@ function isEnglishSignoff(line: string): boolean {
const SIGNATURE_MARKERS: Array<(line: string) => boolean> = [
(l) => /^\s*--\s*$/.test(l),
isEnglishSignoff,
- (l) => /^\s*sent from my (iphone|android|mobile|ipad)/i.test(l),
(l) =>
/^\s*(atenciosamente|att|abraços?|abs|um abraço|cordialmente|grat[oa]|(muito )?obrigad[oa]s?( desde já| pela atenção)?|(com os melhores )?cumprimentos|saudações|(un )?saludos?( cordiales)?|atentamente|(muchas )?gracias( de antemano)?)[\s,!.]*$/i.test(
l,
),
];
const DEVICE =
- "iphone|ipad|android|ios|celular|telemóvel|móvil|galaxy|smartphone|samsung|tablet|" +
+ "iphone|ipad|android|ios|mobile|celular|telemóvel|móvil|galaxy|smartphone|samsung|tablet|" +
"outlook|yahoo|mail|e-?mail|gmail|windows";
const DEVICE_FOOTER = new RegExp(
"^\\s*((enviad[oa] (do|pelo|pela|via|desde|a partir do)( meu| minha| mi)?|sent from( my)?)" +
- ` (${DEVICE})( (${DEVICE}|para|for|no|na|\\d+))*|(obter o|get) outlook (para|for) (ios|android))[\\s.!]*$`,
+ ` (${DEVICE})( (${DEVICE}|para|for|no|na|\\d+|phone|device|pro|max|mini|plus|using [a-z][\\w.+-]*))*` +
+ "|(obter o|get) outlook (para|for) (ios|android))[\\s.!]*$",
"i",
);
const DISCLAIMER = new RegExp(
diff --git a/laya-ts/tests/email-presets.test.ts b/laya-ts/tests/email-presets.test.ts
index 3df2caac..6e60c8a2 100644
--- a/laya-ts/tests/email-presets.test.ts
+++ b/laya-ts/tests/email-presets.test.ts
@@ -15,6 +15,33 @@ describe("email+presets", () => {
expect(out).toContain("Please refund my order");
expect(out).not.toContain("iPhone");
});
+ it("cuts extended device footers (Python parity)", () => {
+ const request = "Please refund my order";
+ for (const footer of [
+ "Sent from my iPhone 15 Pro",
+ "Sent from my Android phone",
+ "Sent from my iPad Pro",
+ "Sent from my iPhone using Tapatalk",
+ "Sent from my iPhone device",
+ "Sent from my iPhone Max",
+ "Sent from my iPhone mini",
+ "Sent from my iPhone Plus",
+ ]) {
+ expect(cleanEmailBody(`${request}\n\n${footer}`), footer).toBe(request);
+ }
+ });
+ it("keeps device mentions inside the request (Python parity)", () => {
+ for (const sentence of [
+ "Sent from my iPhone by mistake.",
+ "Sent from my iPad yesterday.",
+ "Sent from my Android by mistake.",
+ "Sent from my mobile yesterday.",
+ "Sent from my iPhone using Tapatalk to report a problem.",
+ ]) {
+ const body = `Hi support,\n${sentence}\nPlease cancel the duplicate order.`;
+ expect(cleanEmailBody(body), sentence).toBe(body);
+ }
+ });
it("keeps a closing sentence that is not a sign-off (Python parity)", () => {
const body = "Please review the draft when you can.\nIt is two pages.\nThanks for the quick reply.";
expect(cleanEmailBody(body)).toBe(body);
diff --git a/laya/email.py b/laya/email.py
index 2e017bd5..f5d91b84 100644
--- a/laya/email.py
+++ b/laya/email.py
@@ -75,7 +75,8 @@ _DEVICE = (r"iphone|ipad|android|ios|mobile|celular|telemóvel|móvil|galaxy|sma
r"outlook|yahoo|mail|e-?mail|gmail|windows")
_DEVICE_FOOTER = re.compile(
r"^\s*((enviad[oa] (do|pelo|pela|via|desde|a partir do)( meu| minha| mi)?|sent from( my)?)"
- r" (%s)( (%s|para|for|no|na|\d+))*|(obter o|get) outlook (para|for) (ios|android))[\s.!]*$"
+ r" (%s)( (%s|para|for|no|na|\d+|phone|device|pro|max|mini|plus|using [a-z][a-z0-9_.+-]*))*"
+ r"|(obter o|get) outlook (para|for) (ios|android))[\s.!]*$"
% (_DEVICE, _DEVICE),
re.I,
)
diff --git a/tests/test_email.py b/tests/test_email.py
index 4108b07d..d60a5935 100644
--- a/tests/test_email.py
+++ b/tests/test_email.py
@@ -403,16 +403,25 @@ for label, tail in [
("sent from tablet", "Sent from my iPad."),
("sent from android", "Sent from my Android"),
("sent from mobile", "Sent from my mobile"),
+ ("sent from iphone model", "Sent from my iPhone 15 Pro"),
+ ("sent from android phone", "Sent from my Android phone"),
+ ("sent from ipad model", "Sent from my iPad Pro"),
+ ("sent from iphone app", "Sent from my iPhone using Tapatalk"),
("dash delimiter", "--\nAnna Meier\nSupport"),
]:
check("signoff cut/" + label, clean_email_body("%s\n\n%s" % (BODY, tail)), BODY)
+for suffix in ["device", "Max", "mini", "Plus"]:
+ tail = "Sent from my iPhone %s" % suffix
+ check("device footer suffix/" + suffix, clean_email_body("%s\n\n%s" % (BODY, tail)), BODY)
+
# A device mention can describe the request rather than close the message.
for sentence in [
"Sent from my iPhone by mistake.",
"Sent from my iPad yesterday.",
"Sent from my Android by mistake.",
"Sent from my mobile yesterday.",
+ "Sent from my iPhone using Tapatalk to report a problem.",
]:
body = "Hi support,\n%s\nPlease cancel the duplicate order." % sentence
check("device sentence kept/" + sentence, clean_email_body(body), body)