Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

filter unsubscribe emails #1558

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion script/rss2html.ml
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,10 @@ let delete_author title =
let caml_list_re =
Str.regexp_case_fold "^\\(Re: *\\)*\\(\\[[a-zA-Z0-9-]+\\] *\\)*"

(*Remove the unsubscribe emails*)
let unsubscribe_email_re =
Str.regexp_case_fold ".*unsubscribe.*"

(** [email_threads] does basically the same as [headlines] but filter
the posts to have repeated subjects. It also presents the subject
better. *)
Expand All @@ -603,12 +607,13 @@ let email_threads ?n ~l9n url =
let title = delete_author title in
{ e with Atom.title = Atom.Text title } in
let posts = List.map normalize_title posts in
(* Keep only the more recent post of redundant subjects. *)
(* Keep only the more recent post of redundant subjects and filter out the unsubscribe emails *)
let module S = Set.Make(String) in
let seen = ref S.empty in
let must_keep (e: Atom.entry) =
let title = string_of_text_construct e.Atom.title in
if S.mem title !seen then false
else if Str.string_match unsubscribe_email_re title 0 then false
else (seen := S.add title !seen; true) in
let posts = List.filter must_keep posts in
let posts = (match n with
Expand Down