4 # Copyright 2015, Olivier MATZ <zer0@droids-corp.org>
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions are met:
9 # * Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
11 # * Redistributions in binary form must reproduce the above copyright
12 # notice, this list of conditions and the following disclaimer in the
13 # documentation and/or other materials provided with the distribution.
14 # * Neither the name of the University of California, Berkeley nor the
15 # names of its contributors may be used to endorse or promote products
16 # derived from this software without specific prior written permission.
18 # THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
19 # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 # DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
22 # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25 # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 # This is an example of how imapami can be extended in python. The
32 # following code creates a new condition class that is registered. The
33 # same can be done for actions.
35 # After that, the script calls imapami.run() which behaves like imapami
36 # with the new condition registered.
40 import imapami.conditions
42 class ImapamiCondList(imapami.conditions.ImapamiCond):
44 Match if the sender is present in the file.
46 The file is a list of mails, one per line.
49 file: <string> [mandatory]
50 The path to the balcklist file.
53 list: {filename: /home/user/list.txt}
57 def __init__(self, filename):
58 ImapamiCond.__init__(self, fetch='headers')
59 self.filename = filename
61 def check(self, imapami_handler, msg_id, hdrs, body_part1, body_all):
62 From = self.evaluate("{From}", imapami_handler, hdrs)
64 f = open(self.filename)
69 if From.lower() == l[:-1].lower():
72 imapami_handler.logger.warning("error opening list file <%s>")
74 imapami.conditions.register(ImapamiCondList)
76 if __name__ == '__main__':