166 lines · 8.8 KB · RustRaw
//! Person or machine. Every address is invented.use super::*;fn of(address: &str) -> Facts<'_> { Facts { address, ..Facts::default() }}#[test]fn a_block_is_junk_above_everything() { let facts = Facts { blocked: true, in_people: true, written_to: true, owner_verdict: Some("person"), ..of("asha@example.com") }; assert_eq!(who(&facts), (Who::Junk, Why::Blocked));}#[test]fn the_owners_verdict_is_above_people_and_every_guess() { assert_eq!(who(&Facts { owner_verdict: Some("service"), in_people: true, ..of("asha@example.com") }), (Who::Machine, Why::OwnerSaid)); assert_eq!(who(&Facts { owner_verdict: Some("person"), ..of("no-reply@shop.example") }), (Who::Person, Why::OwnerSaid)); assert_eq!(who(&Facts { owner_verdict: Some("junk"), ..of("asha@example.com") }), (Who::Junk, Why::OwnerSaid));}#[test]fn someone_in_people_is_a_person_even_at_a_role_address() { assert_eq!(who(&Facts { in_people: true, ..of("support@bimal-tours.example") }), (Who::Person, Why::InPeople));}#[test]fn a_machine_shaped_address_is_a_machine_even_when_written_to() { for address in ["noreply@shop.example", "no-reply@bank.example", "do_not_reply@air.example", "bounce-123@mail.example", "MAILER-DAEMON@mx.example", "team-request@lists.example.org", "club@googlegroups.com"] { assert_eq!(who(&Facts { written_to: true, ..of(address) }), (Who::Machine, Why::MachineShaped), "{address}"); }}#[test]fn role_mailboxes_are_machines() { for address in ["notifications@code.example", "news@paper.example", "billing-team@cloud.example", "info@hotel.example", "support+case12@app.example", "hello@startup.example", "receipts.in@ride.example"] { assert!(is_machine_shaped(address), "{address}"); } for address in ["asha@example.com", "asha.info@example.com", "newsom@example.com", "teamwork.ravi@example.com", "helen@example.com"] { assert!(!is_machine_shaped(address), "{address}"); }}#[test]fn someone_the_owner_wrote_to_is_a_person() { assert_eq!(who(&Facts { written_to: true, ..of("ravi.k@example.net") }), (Who::Person, Why::WrittenTo));}#[test]fn the_old_readers_word_holds_when_nothing_above_answers() { assert_eq!(who(&Facts { stored_kind: Some("person"), ..of("meera@example.org") }), (Who::Person, Why::OldReader)); assert_eq!(who(&Facts { stored_kind: Some("service"), ..of("meera@example.org") }), (Who::Machine, Why::OldReader)); // A stored person never beats a machine shape: the shape is above it. assert_eq!(who(&Facts { stored_kind: Some("person"), ..of("alerts@bank.example") }), (Who::Machine, Why::MachineShaped));}/// The old reader called everyone it did not know `service`: that says nothing against a person's look.#[test]fn the_old_readers_service_is_no_word_against_a_person() { assert_eq!(who(&Facts { stored_kind: Some("service"), name: Some("Nina Gale"), ..of("nina.gale@outlook.com") }), (Who::Person, Why::LooksPersonal));}#[test]fn a_stranger_with_no_look_of_a_person_waits_as_a_machine() { assert_eq!(who(&of("someone.new@example.com")), (Who::Machine, Why::Stranger)); assert_eq!(who(&Facts { stored_kind: Some("junk"), ..of("someone.new@example.com") }), (Who::Machine, Why::Stranger)); assert_eq!(who(&Facts { name: Some("Joe"), ..of("joe@parcel.example") }), (Who::Machine, Why::Stranger));}/// RULE (who_corpus.txt): a stranger who writes as a person is one: a webmail mailbox, or their full name made/// into the address. They wait in the Mail tab under People; only someone in People reaches a conversation.#[test]fn a_stranger_who_looks_like_a_person_is_one() { for (name, address) in [ (None, "hannah.cole@ymail.com"), (Some("Uncle Raj"), "rajesh.iyer@yahoo.co.in"), (Some("Aunty"), "lakshmi.n@hotmail.co.uk"), (Some("Diego Ramos"), "diego@work.example"), (Some("Mark Ellis"), "mark@markellis.example"), (Some("Peter Novak"), "pnovak@client.example"), (Some("Ahmed Hassan"), "ahmed.h@uni.example"), (Some("Marcus Brown"), "marcus.brown2@work.example"), ] { assert_eq!(who(&Facts { name, ..of(address) }), (Who::Person, Why::LooksPersonal), "{address}"); } // A word of a name inside the address is not a name made into it. for (name, address) in [("Credit Card", "cards@bank.example"), ("Brew Co", "ravi@brewco.example"), ("Diego", "diego@work.example")] { assert_eq!(who(&Facts { name: Some(name), ..of(address) }), (Who::Machine, Why::Stranger), "{address}"); }}/// RULE: bulk senders' domains and the labels they put before a shop's domain are machine-shaped, as are the role/// mailboxes the corpus found missing.#[test]fn bulk_domains_and_more_role_mailboxes_are_machines() { for address in [ "slowreading@substack.com", "channing@mail.beehiiv.com", "maria@buttondown.email", "reply@rs.email.nextdoor.example", "deals@news.shop.example", "tickets@movies.example", "confirmations@air.example", "ebill@power.example", "invitations@social.example", "weekly@techweekly.example", ] { assert!(is_machine_shaped(address), "{address}"); } // A university's people write from mail.; Bill is a name. for address in ["asha@mail.uni.example", "bill@work.example", "asha@email-studio.example"] { assert!(!is_machine_shaped(address), "{address}"); }}/// RULE: a name a company or a service sends as is machine-shaped, above having been written to.#[test]fn a_service_shaped_name_is_a_machine() { for name in ["Asha Rao (via Google Docs)", "Ravi Kumar via LinkedIn", "'Nisha' via Wedding Planning", "Sarah from Acme", "Mike at Notely", "Jake @ Fitbox", "The Acme Team", "Acme Support", "Mail Delivery Subsystem"] { assert_eq!(who(&Facts { name: Some(name), written_to: true, ..of("someone@example.com") }), (Who::Machine, Why::MachineShaped), "{name}"); } for name in ["Asha Rao", "Tom Atkins", "Viaan Shah", "Fromm Erich", "Bimal (Bimal Tours)"] { assert!(!is_machine_name(name), "{name}"); }}/// RULE: mail whose sender's own words carry a bulk footer, whose subject is a calendar's or a bounce's, or that/// went to a list and not to the person, is a machine's; what a friend forwarded is not their words.#[test]fn machine_made_mail_is_a_machines() { let text = |text| Facts { name: Some("Pat Kelly"), text: Some(text), ..of("pat@patkelly.example") }; for words in [ "Here's my month. If you'd rather not get these, unsubscribe below.", "New knits. Update your email preferences.", "Top stories. View this email in your browser.", "You're receiving this because you signed up.", "This is an automated message, please do not reply.", "Your payslip is ready. This is a system-generated mail.", "© 2026 Pat Co.", "Dear Customer, your bill is ready.", // Found by the held-out set, each a kind and not one sender: any automated thing, and a greeting to many. "This is an automated reminder of your appointment.", "Dear customers, we are moving to Station Road.", "To opt out of future emails, reply STOP.", ] { assert_eq!(who(&text(words)), (Who::Machine, Why::MachineMade), "{words}"); } let subject = |subject| Facts { name: Some("Jennifer Lee"), subject: Some(subject), ..of("jlee@work.example") }; for words in ["Invitation: Q4 planning @ Tue 3pm", "Accepted: Lunch @ Fri", "Undeliverable: Q3 numbers", "Delivery Status Notification (Failure)"] { assert_eq!(who(&subject(words)), (Who::Machine, Why::MachineMade), "{words}"); } assert_eq!(who(&Facts { name: Some("Ravi Menon"), to_a_list: true, ..of("ravimenon88@ymail.com") }), (Who::Machine, Why::MachineMade)); let forwarded = "For the trip!\n\n---------- Forwarded message ---------\nFrom: Air <confirmations@air.example>\nUnsubscribe."; assert_eq!(who(&Facts { name: Some("Ravi Menon"), text: Some(forwarded), ..of("ravimenon88@ymail.com") }), (Who::Person, Why::LooksPersonal)); let begun = "Please do this today.\n\nBegin forwarded message:\nThis is an automated email, please do not reply."; assert_eq!(who(&Facts { text: Some(begun), ..of("k.iyer@ymail.com") }), (Who::Person, Why::LooksPersonal)); // People talk about automatic things too: only an automated message, mail, reminder or alert says a machine. assert_eq!(who(&Facts { text: Some("I turned off the automatic updates on your laptop, and got an automatic reply from Ravi."), ..of("k.iyer@ymail.com") }), (Who::Person, Why::LooksPersonal)); // A person's words about unsubscribing are a person's when the person has written to them. assert_eq!(who(&Facts { written_to: true, text: Some("I tried to unsubscribe, hopeless"), ..of("asha@example.com") }), (Who::Person, Why::WrittenTo));}#[test]fn an_address_without_an_at_is_a_machine() { assert!(is_machine_shaped("undisclosed-recipients"));}