#!/usr/bin/env python2.2

# version 0.0.1
# Author: Tjabo Kloppenburg, tk at  taponet.de
# Date  : 2002 Dec 01
# TISNOP is [not:)] a new mail filter written in python.

# TSNOP = This Is NOt Procmail

import sys
import re
import tisnop          # 0.0.1

t1 = tisnop.tisnop( sys.stdin.read() )  # do not change this!

# --------------------------------------------------------------
# Configuration section:

# Conditions:

c_texthtml = \
  tisnop.condition(
      "pure html mail",
      tisnop.HEADER,
      "Content-type",
      re.compile("text/html")  )


c_5space   = \
  tisnop.condition(
      "too many space chars",
      tisnop.HEADER,
      "Subject",
      re.compile("\s{5}")  )


c_3nums    = \
  tisnop.condition(
      "three numbers in From",
      tisnop.HEADER,
      "From",
      re.compile("[0-9]{3}")  )


c_from_me  = \
  tisnop.condition(
      "comes from me",
      tisnop.HEADER,
      "From",
      re.compile("tk@taponet\.de", re.I)  )


c_nomagic  = \
  tisnop.condition(
      "magic missing",
      tisnop.HEADER,
      "Subject",
      re.compile("^(?!tapo)")  )


# Actions:

a_mark_spam = \
  tisnop.action(
      "MARK_SPAM",  tisnop.HEADER, "Subject", "SPAM: %S" )

a_dev_null = \
  tisnop.action(
      "DISCARD MAIL",  tisnop.DEVNULL, "", "" )


c_5space.test()
c_3nums.test()
c_from_me.test()
c_nomagic.test()
c_texthtml.test()

t1.addRule( "Only HTML Content"     , [c_texthtml], [a_mark_spam] )
t1.addRule( "possible_fake_from"    , [c_3nums]   , [a_mark_spam] )
t1.addRule( "five spaces in subject", [c_5space]  , [a_mark_spam] )

# End of configuration
# --------------------------------------------------------------

t1.action()

