index all rss twitter github linkedin email
Álvaro Ramírez

Álvaro Ramírez

08 October 2019 Spam blacklisting with Emacs org babel

Some email provider accept regular expressions to blacklist additional spam. My blacklist is long and tedious to update, but hey… Emacs org babel can simplify things here.

It's way easier to maintain a blacklist (with no regex) using an org table.


#+name: spam-entries
| .spammy                |
| |
|    |
|            |

and subsequently use org babel (elisp snippet) to generate the regex.

Regex gen

#+begin_src emacs-lisp :var rows=spam-entries
  (require 'dash)
  (require 's)

  (concat "^"
          (s-join "|"
                  (mapcar (lambda (entry)
                            (setq entry (regexp-quote
                                         (s-trim entry)))
                            (assert (s-present? entry))
                             ;; Blacklist email address: joe@spammer.spammy
                             ((s-contains-p "@" entry)
                              (format "(%s)" entry))
                             ;; Blacklist top-level domain: .spammy
                             ((s-starts-with-p "\\." entry)
                              (format "([^.]*%s)" entry))
                             ;; Blacklist domain: @spammer.spammy
                              (format "(.*@%s)" entry))))
                           (-map (lambda (row)
                                   (nth 0 row))


: ^([^.]*\.spammy)|(dodgyfella@hotmail\.com)|(.*@henryzeespammer\.com)|(.*@yumspam\.com)$

UPDATE: Tweaked elisp and regex (but not animation) also found John Bokma's post: Blacklisting domains with Postfix.